Re: Calendar.GetFinishDateByStartAndWork Method

Hi,

I have a question about this method.
Does this method calculates the finish date without the weekends?

For example, if the start date is on Wednesday and the duration is 5 days, the final date will be on the next Tuesday or will it be Sunday?

What do I need to do to calculate the finish date without the weekends?

DLLs:
Aspose.Tasks - Version: 4.4.0.0
Aspose.Cells - Version: 7.1.2.0

Thanks

Hi Ricardo,


Thank you for contacting Aspose support team.

Calendar.GetFinishDateByStartAndWork() works based upon the week days set in the calendar. By default Saturday and Sunday are off days, therefore in your scenario the final date will be Tuesday. However in order to calculate finish date without weekends, you need to modify the calendar. This can be achieved by using Aspose.Tasks as given below:

Aspose.Tasks.Calendar cal = new Aspose.Tasks.Calendar();
cal.Days.Add(WeekDay.CreateDefaultWorkingDay(DayType.Monday));
cal.Days.Add(WeekDay.CreateDefaultWorkingDay(DayType.Tuesday));
cal.Days.Add(WeekDay.CreateDefaultWorkingDay(DayType.Wednesday));
cal.Days.Add(WeekDay.CreateDefaultWorkingDay(DayType.Thursday));
cal.Days.Add(WeekDay.CreateDefaultWorkingDay(DayType.Friday));
cal.Days.Add(WeekDay.CreateDefaultWorkingDay(DayType.Saturday));
cal.Days.Add(WeekDay.CreateDefaultWorkingDay(DayType.Sunday));
DateTime dt = cal.GetFinishDateByStartAndWork(new DateTime(2014, 7, 9, 8, 0, 0), new TimeSpan(40, 0, 0));

You may also get more information for working with calendar as given below:
Please feel free to write us back if you have any other query in this regard.