Hi, I tried some other settings and ran into another problem.
I manually created a 24hour (worktime each day) calendar and compared that with using a 23 hour and 59 minutes calendar. For the 23 hour (59 minutes) Calendar it worked fine, but for the 24 hour calendar the startdates and duration became incorrect.
I don’t know if this is caused by the same error as discovered earlier, or if it is another one (Or if I’m doing something wrong). Nevertheless, I wanted to check with you guys.
I attached both the generated xml files for the two cases.
double task1Duration = 5; //Monday to friday
double weekend = 2; // saturday and sunday
double task2Duration = 3; //Monday to wednesday
DateTime projectStartDateTime = new DateTime(2015, 7, 27, 0, 0, 0);
DateTime projectFinishDateTime = projectStartDateTime.AddDays(task1Duration + weekend + task2Duration);
DateTime task1StarDateTime = projectStartDateTime; //Monday
DateTime task2StarDateTime = new DateTime(2015, 8, 3, 0, 0, 0); //Next Monday
var asposeProject = new Project();
asposeProject.Set(Prj.Name, “Project1”);
asposeProject.Set(Prj.StartDate, projectStartDateTime);
asposeProject.Set(Prj.FinishDate, projectFinishDateTime);
asposeProject.Set(Prj.WeekStartDay, DayType.Monday);
asposeProject.Set(Prj.DurationFormat, TimeUnitType.Day);
var startTimeMorning = new DateTime(2015, 1, 14, 0, 0, 0);
//var finishTimeEvening = new DateTime(2015, 1, 14, 23, 59, 0); //23 hour 59 minutes
var finishTimeEvening = new DateTime(2015, 1, 15, 0, 0, 0); //24 hour calendar
var minutesPerDay = (int)finishTimeEvening.Subtract(startTimeMorning).TotalMinutes;
asposeProject.Set(Prj.MinutesPerDay, minutesPerDay);
asposeProject.Set(Prj.DefaultStartTime, startTimeMorning);
asposeProject.Set(Prj.DefaultFinishTime, finishTimeEvening);
var asposeCalendar = asposeProject.Calendars.Add(“24hourCal”);
foreach (var weekDay in asposeCalendar.WeekDays)
{
//Remove default
List asposeWorkingTimesRemove = weekDay.WorkingTimes.ToList();
foreach (var workingTime in asposeWorkingTimesRemove)
{
weekDay.WorkingTimes.Remove(workingTime);
}
//Add worktimes
weekDay.WorkingTimes.Add(new WorkingTime() { FromTime = startTimeMorning, ToTime = finishTimeEvening });
if (weekDay.DayType.Equals(DayType.Saturday) || weekDay.DayType.Equals(DayType.Sunday))
{
weekDay.DayWorking = false;
}
else
{
weekDay.DayWorking = true;
}
}
var task1 = asposeProject.RootTask.Children.Add(“Task1”);
task1.Set(Tsk.Calendar, asposeCalendar);
task1.Set(Tsk.IsManual, true);
task1.Set(Tsk.DurationFormat, TimeUnitType.Day);
task1.Set(Tsk.Duration, asposeProject.GetDuration(task1Duration));
task1.Set(Tsk.Start, task1StarDateTime); //Monday
var task2 = asposeProject.RootTask.Children.Add(“Task2”);
task2.Set(Tsk.Calendar, asposeCalendar);
task2.Set(Tsk.IsManual, true);
task2.Set(Tsk.DurationFormat, TimeUnitType.Day);
task2.Set(Tsk.Duration, asposeProject.GetDuration(task2Duration));
task2.Set(Tsk.Start, task2StarDateTime); //Monday