Adding and Removing Calendar Exceptions

Working with Calendar Exceptions The CalendarException class is used to represent a Calendar Exception object. The ExceptionCollection class can be obtained by using the Project class’s getCalendars() method that can be used to retrieve existing exceptions, manage new exceptions added to it and remove existing exceptions.

Programming Sample

The following examples show how to add, remove and display exceptions using Java.

 1// The path to the documents directory.
 2String dataDir = Utils.getDataDir(AddRemoveCalendarExceptions.class);
 3
 4Project project = new Project(dataDir + "input.mpp");
 5
 6//Remove an exception
 7Calendar cal = project.getCalendars().toList().get(0);
 8if (cal.getExceptions().size() > 1)
 9{
10        CalendarException exc = cal.getExceptions().toList().get(0);
11        cal.getExceptions().remove(exc);
12}
13
14//Add an exception
15CalendarException calExc = new CalendarException();
16
17java.util.Calendar calObject = java.util.Calendar.getInstance();
18calObject.set(2009, 1, 1, 0, 0, 0);
19calExc.setFromDate(calObject.getTime());
20
21calObject.set(2009, 1, 3, 0, 0, 0);
22calExc.setToDate(calObject.getTime());
23
24cal.getExceptions().add(calExc);
25
26//Display exceptions
27for(CalendarException calExc1:cal.getExceptions())
28{
29    System.out.println("From" + calExc1.getFromDate().toString());
30    System.out.println("To" + calExc1.getToDate().toString());
31}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.