{
ProjectCalendarWeek week = mpxjCalendar.addWorkWeek();
week.setName(xmlWeek.getName());
Date startTime = DatatypeConverter.parseDate(xmlWeek.getTimePeriod().getFromDate());
Date endTime = DatatypeConverter.parseDate(xmlWeek.getTimePeriod().getToDate());
week.setDateRange(new DateRange(startTime, endTime));
WeekDays xmlWeekDays = xmlWeek.getWeekDays();
if (xmlWeekDays != null)
{
for (WeekDay xmlWeekDay : xmlWeekDays.getWeekDay())
{
int dayNumber = xmlWeekDay.getDayType().intValue();
Day day = Day.getInstance(dayNumber);
week.setWorkingDay(day, BooleanUtility.getBoolean(xmlWeekDay.isDayWorking()));
ProjectCalendarHours hours = week.addCalendarHours(day);
Project.Calendars.Calendar.WorkWeeks.WorkWeek.WeekDays.WeekDay.WorkingTimes times = xmlWeekDay.getWorkingTimes();
if (times != null)
{
for (Project.Calendars.Calendar.WorkWeeks.WorkWeek.WeekDays.WeekDay.WorkingTimes.WorkingTime period : times.getWorkingTime())
{
startTime = DatatypeConverter.parseTime(period.getFromTime());
endTime = DatatypeConverter.parseTime(period.getToTime());
if (startTime != null && endTime != null)
{
if (startTime.getTime() >= endTime.getTime())
{
Calendar cal = Calendar.getInstance();
cal.setTime(endTime);
cal.add(Calendar.DAY_OF_YEAR, 1);
endTime = cal.getTime();
}
hours.addRange(new DateRange(startTime, endTime));
}
}
}
}
}