Solution ID: prim80230
Sample Java code to retrieve the valid work periods of a calendar on specific days or a range of days through the Integration API.
Status: Reviewed
Version(s): 6.0, 6.1, 6.2, 6.2.1

Problem: How to retrieve the valid work periods of a calendar on specific days or a range of days through the Integration API?
Problem: How to report on a calendar through the API.
Fix: NOTE: The following sample code will print the date and valid work periods of the calendar with the name “Standard 5 Day Workweek w/ Basic Holidays” for every day in the year 2009:

java.util.Calendar mycalstart = java.util.Calendar.getInstance();
mycalstart.set(2009, 0, 1);
Date startdate = mycalstart.getTime();
  
java.util.Calendar mycalfinish = java.util.Calendar.getInstance();
mycalfinish.set(2010, 0, 1);
Date finishdate = mycalfinish.getTime();
  
try{
    
   EnterpriseLoadManager elm = mySession.getEnterpriseLoadManager();
   BOIterator boical = elm.loadCalendars(new String[]{“Name”}, “Name = ‘Standard 5 Day Workweek w/ Basic Holidays’”, null);
     
   while(boical.hasNext()){
      Calendar cal = (Calendar)boical.next();
      System.out.println(cal.getName());
      System.out.println();
      System.out.println(“***************************************************”);
      System.out.println();

      while(startdate.getTime() < finishdate.getTime()){
         System.out.println(startdate);
         System.out.println(“   Valid Work Time(s): ” + cal.getDetailedWorkHours(startdate).getTimeString());
         mycalstart.add(java.util.Calendar.HOUR, 24);
         startdate = mycalstart.getTime();


      }
   }
}


The output of the above sample code will look something like this:


Standard 5 Day Workweek w/ Basic Holidays


***************************************************


Thu Jan 01 12:43:25 GMT-05:00 2009
   Valid Work Time(s):
Fri Jan 02 12:43:25 GMT-05:00 2009
   Valid Work Time(s): 08:00-11:59;13:00-16:59
Sat Jan 03 12:43:25 GMT-05:00 2009
   Valid Work Time(s):
Sun Jan 04 12:43:25 GMT-05:00 2009
   Valid Work Time(s):
Mon Jan 05 12:43:25 GMT-05:00 2009
   Valid Work Time(s): 08:00-11:59;13:00-16:59
Tue Jan 06 12:43:25 GMT-05:00 2009
   Valid Work Time(s): 00:00-23:59
Wed Jan 07 12:43:25 GMT-05:00 2009
   Valid Work Time(s): 08:00-11:59;13:00-16:59