Start and Finish dates do not accept weekend dates (C# .NET)

Hello ASPOSE,

This ticket is strongly related to Start and Finish dates of task not getting reflected .

As an input for exporting into .mpp file I have got Start date and Finish date . I need to transfer those dates info .mpp file without changes.

From the ticket mentioned above Mr. Kashif Iqbal says: “The recommended method to set task parameters is to use task start date and duration. It will make no change in the constraint type and date as well.”

I followed the ticket until the end, but unfortunately with no positive results.

Finally, with some tweaks I have got this code.

task.Set(Tsk.Start, Convert.ToDateTime(“2019,07,08”));

double totalHours = cal.GetWorkingHours(Convert.ToDateTime(“2019,07,08”), Convert.ToDateTime(“2019,07,22”)).WorkingHours.TotalHours;

totalHours += 8;

task.Set(Tsk.Duration, project.GetDuration(totalHours, TimeUnitType.Hour));

In most cases this code gave me those dates preserved. But there were exceptions.

If any date is Saturday or Sunday, the result is always next Monday.

How to allow weekend dates?

How to keep StartDates and FinishDates unchanged against input values?

Thank you for your time.

@novotny,

I have observed your requirements and like to share that by default Saturday and Sunday are considered as off days owing to weekend. If you want them to be working days, you need to modify the calendar and set the days to be working. I request you to please visit following thread for your kind reference.

Thank you Mr. Fayyaz for quick response.
The ticket you’re mentioned served me as a clue.
I changed my code into something like this:


Aspose.Tasks.Calendar cal = project.Get(Prj.Calendar);
foreach (var item in cal.WeekDays)
item.DayWorking = true;
Task task = parentTask.Children.Add(“something”);
task.Set(Tsk.ConstraintType, ConstraintType.MustStartOn);
task.Set(Tsk.Start, Convert.ToDateTime(“2019,07,06”));
task.Set(Tsk.Finish, Convert.ToDateTime(“2019,07,27”));

Finish date is now ok, but Start date is still shifted to next Monday.

@novotny,

I have observed your requirements and like to share that you may need to set Saturday or Sunday as working days in your calendar to avoid issue. Please visit this documentation link for your kind reference.

Looks like the line:

project.Set(Prj.Calendar, Aspose.Tasks.Calendar.Make24HourCalendar(project.Calendars.Add("24 Hour")));

does the magic for me.
For me this thread is solved.

Note: Your documentation link was useful and I really thank you for it. But… Even thou this was probably beginner question. Giving me straight answer + documentation link would make journey less painful.

@novotny,

Thank you for your kind feedback that things are resolved on your end.