Add 24 hour Calendar

Hi,

I’m editing an empty mpp file and adding tasks to it. Our standard day has 2x12 hour shifts: one from 6 AM to 6 PM, and the other from 6 PM to 6 AM. This is the only calendar the project needs.

I create the calendar with the following code:

CalendarCollection calColl = _project.Calendars;
foreach (Calendar c in calColl)
{
    if (c.Name == "24hourCal")
    {
        calColl.Remove(c);
        break;
    }
}
WorkingTime wt1 = new WorkingTime();
wt1.FromTime = new DateTime(1, 1, 1, 6, 0, 0, 0);
wt1.ToTime = new DateTime(1, 1, 1, 18, 0, 0, 0);
WorkingTime wt2 = new WorkingTime();
wt2.FromTime = new DateTime(1, 1, 1, 18, 0, 0, 0);
wt2.ToTime = new DateTime(1, 1, 2, 6, 0, 0, 0);
var asposeCalendar = _project.Calendars.Add("24hourCal");
Calendar.Make24HourCalendar(asposeCalendar);
foreach (var weekDay in asposeCalendar.WeekDays)
{
    List<WorkingTime> asposeWorkingTimesRemove = weekDay.WorkingTimes.ToList();
    foreach (var workingTime in asposeWorkingTimesRemove)
    {
        weekDay.WorkingTimes.Remove(workingTime);
    }
    //Add worktimes
    weekDay.WorkingTimes.Add(wt1);
    weekDay.WorkingTimes.Add(wt2);
    weekDay.DayWorking = true;
}
_project.Set(Prj.Calendar, asposeCalendar);

When I open the mpp file in MS-Project, my Gantt chart bars that lye on a standard calendar’s non-work time are not plotting. When I check the definition of my new calendar “24hourCal”, my work times do not exist, and only the standard calendar’s work times are shown. What am I doing wrong?

Cheers

Ian

Hi Ian,


Thank you for writing to Aspose support team.

I have tried to generate this calendar using Aspose.Tasks but could not succeed and observed the same issue in MPP as mentioned by you. However I was also not able to generate such calendar using Microsoft Project (MSP 2010). Could you please generate similar calendar in a sample project using MSP, save this project as XML and MPP and send us both these files (generated by MSP) for our analysis here? It will help us to compare the results and provide assistance accordingly.

HI,


Please find requested files attached.

Thanks,
Ian

Hi Ian,

I have analyzed the sample files but could not open the XML file in MSP 2010 as there are many issues in the XML file which fails MSP to open it.

In the MPP file I opened it in MSP 2010 but could not view the calendar which contains times from 6 am to 6 pm and 6 am to 6 pm. As requested earlier, please try creating such calendar using MSP, where start/finish times are 6 am to 6 pm and from 6 pm to 6 am. I tried this using MSP 2010 but could not generate similar calendar.

Please send us some template file, XML and MPP both (even without any task), which contains such calendar. It will help us to provide assistance accordingly.