Hi,
I’d like to set working time from 8:00 to 11:00 and from 13:00 to 16:00, but it doesn’t work, please see the attachment.
Below is the code:
public static void main(String[] args) throws ParseException {
FileInputStream fstream = null;
try {
// Create a stream object containing the license file
fstream = new FileInputStream(“Aspose.Tasks.lic”);
// Instantiate the License class
License license = new License();
// Set the license through the stream object
license.setLicense(fstream);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fstream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Project asProject = new Project(“Empty_Project.mpp”);
// Define Calendar
Calendar cal = asProject.getCalendars().add(“Calendar1”);
Calendar.makeStandardCalendar(cal);
for (WeekDay wd : cal.getWeekDays()) {
if(wd.getDayWorking()) {
WorkingTime wt1 = new WorkingTime();
java.util.Calendar calTime = java.util.Calendar.getInstance();
calTime.set(1,1,1,8,0,0);
wt1.setFromTime(calTime.getTime());
calTime.set(1,1,1,11,0,0);
wt1.setToTime(calTime.getTime());
WorkingTime wt2 = new WorkingTime();
calTime.set(1,1,1,13,0,0);
wt2.setFromTime(calTime.getTime());
calTime.set(1,1,1,16,0,0);
wt2.setToTime(calTime.getTime());
wd.getWorkingTimes().add(wt1);
wd.getWorkingTimes().add(wt2);
wd.setDayWorking(true);
}
}
asProject.set(Prj.CALENDAR, cal);
asProject.save(“output_test_set_calendar2.mpp”, SaveFileFormat.MPP);
}
zhencheng.guo
Best Regards!