gpt4 book ai didi

java - 如何在 MPXJ 中将周末设置为工作日

转载 作者:行者123 更新时间:2023-12-01 12:22:50 29 4
gpt4 key购买 nike

我正在通过 MPXJ 库导出 MS Project 中的项目,我有一个问题:
如何将特定日期周六(或周日)设置为工作日而不是周末? (在 ProjectCalendar 或其他地方)
例如2014年10月18日(星期六)设置为工作日,但其他星期六需要为周末。

public ProjectCalendar initCalendar(ProjectFile projectfile, int calendarId, Date startDate, Date endDate) { 
ProjectCalendar defaultCalendar = projectfile.addDefaultBaseCalendar();

/*Setup standart working week*/
defaultCalendar.setName("Standart");
defaultCalendar.setWorkingDay(Day.MONDAY, DayType.WORKING);
defaultCalendar.setWorkingDay(Day.THURSDAY, DayType.WORKING);
defaultCalendar.setWorkingDay(Day.WEDNESDAY, DayType.WORKING);
defaultCalendar.setWorkingDay(Day.TUESDAY, DayType.WORKING);
defaultCalendar.setWorkingDay(Day.FRIDAY, DayType.WORKING);
defaultCalendar.setWorkingDay(Day.SATURDAY, DayType.NON_WORKING);
defaultCalendar.setWorkingDay(Day.SUNDAY, DayType.NON_WORKING);


ProjectCalendarHours pch;
pch = defaultCalendar.addCalendarHours(Day.MONDAY);
pch.addRange(ProjectCalendar.DEFAULT_WORKING_MORNING);
pch.addRange(ProjectCalendar.DEFAULT_WORKING_AFTERNOON);

pch = defaultCalendar.addCalendarHours(Day.THURSDAY);
pch.addRange(ProjectCalendar.DEFAULT_WORKING_MORNING);
pch.addRange(ProjectCalendar.DEFAULT_WORKING_AFTERNOON);

pch = defaultCalendar.addCalendarHours(Day.WEDNESDAY);
pch.addRange(ProjectCalendar.DEFAULT_WORKING_MORNING);
pch.addRange(ProjectCalendar.DEFAULT_WORKING_AFTERNOON);

pch = defaultCalendar.addCalendarHours(Day.TUESDAY);
pch.addRange(ProjectCalendar.DEFAULT_WORKING_MORNING);
pch.addRange(ProjectCalendar.DEFAULT_WORKING_AFTERNOON);

pch = defaultCalendar.addCalendarHours(Day.FRIDAY);
pch.addRange(ProjectCalendar.DEFAULT_WORKING_MORNING);
pch.addRange(ProjectCalendar.DEFAULT_WORKING_AFTERNOON);


/* setup holydays*/
List<Date> workingHollidays = DBHelper.getWorkingHolidays(ppmCalendarId, startDate, endDate);
for (Date work : workingHollidays) {
ProjectCalendarException ex = defaultCalendar.addCalendarException(work, work);
}

/*There is I need change stendart week and setup 6-days working week (Saturday is work day) */
/*something like that*/
Date workindDay = new SimpleDateFormat("dd.MM.yyyy").parse("18.10.2014");
defaultCalendar.setWorkingDay(workindDay, DayType.NON_WORKING); // This code not work
pch = defaultCalendar.addCalendarHours(workindDay); // This code not work
pch.addRange(ProjectCalendar.DEFAULT_WORKING_MORNING);
pch.addRange(ProjectCalendar.DEFAULT_WORKING_AFTERNOON);
}

并且在输出 Microsoft Project xml 中将是这样的标记:

<Calendar>
...
<WeekDay>
<DayType>
0
</DayType>
<DayWorking>
1
</DayWorking>
<TimePeriod>
<FromDate>2014-10-18T00:00:00</FromDate>
<ToDate>2014-10-18T23:59:00</ToDate>
</TimePeriod>
<WorkingTimes>
<WorkingTime>
<FromTime>09:00:00</FromTime>
<ToTime>13:00:00</ToTime>
</WorkingTime>
<WorkingTime>
<FromTime>14:00:00</FromTime>
<ToTime>18:00:00</ToTime>
</WorkingTime>
</WorkingTimes>
</WeekDay>
...
</Calendar>

谢谢。

最佳答案

我找到了答案。
有将自定义日期设置为工作日期的代码:

Date workindDay = new SimpleDateFormat("dd.MM.yyyy").parse("18.10.2014"); 
ProjectCalendarException ex = defaultCalendar.addCalendarException(workindDay, workindDay);
ex.addRange(ProjectCalendar.DEFAULT_WORKING_MORNING);
ex.addRange(ProjectCalendar.DEFAULT_WORKING_AFTERNOON);

范围的顺序很重要。

关于java - 如何在 MPXJ 中将周末设置为工作日,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26550150/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com