Integration scenarios

Jollyday may be integrated with other open source frameworks to make use of holidays. Some integration examples are sketched out here.

Quartz Scheduler API

Quartz is a full-featured, open source job scheduling service that can be integrated with, or used along side virtually any Java EE or Java SE application - from the smallest stand-alone application to the largest e-commerce system. Quartz can be used to create simple or complex schedules for executing tens, hundreds, or even tens-of-thousands of jobs; jobs whose tasks are defined as standard Java components that may execute virtually anything you may program them to do. The Quartz Scheduler includes many enterprise-class features, such as JTA transactions and clustering.

Jollyday may be integrated with the Quartz Scheduler API be creating a holiday calendar backed by HolidayManager instances. Thus you can automatically have scheduled jobs which will not be triggered during holiday times.

Here is an example implementation for the code integration:

public class JollydayCalendar extends HolidayCalendar {
        
        private String calendarName;
        
        public JollydayCalendar(String calendarName, Calendar baseCalendar, TimeZone tz){
                super(baseCalendar, tz);
                this.calendarName = calendarName;
        }
        
        @Override
        public SortedSet getExcludedDates() {
                java.util.Calendar c = 
                        super.getTimeZone() == null
                        ? java.util.Calendar.getInstance() 
                        : java.util.Calendar.getInstance(super.getTimeZone());
                Set<Holiday> holidays = HolidayManager.getInstance(calendarName).getHolidays(c.get(java.util.Calendar.YEAR));
                TreeSet<LocalDate> dates = new TreeSet<LocalDate>();
                for(Holiday h : holidays){
                        dates.add(h.getDate());
                }
                return dates;
        }
}

ObjectLabKit

ObjectLab Kit came out of our frustration to have to re-do the same kind of code over and over each time we joined a new company and Bank. Most banks will require basic Date calculation, we did spot another open source project for this but their licence forbids most financial institution from using it.

This example is taken from the frameworks main page and modified to use Jollyday. Here you can see how seamlessly it can be integrated with Jollyday:

HolidayManager manager = HolidayManager.getInstance("UK"); // get UK HolidayManager
        
// create or get the Holidays
final Set<Holiday> holidays = manager.getHolidays(2006);

// fill dates into set of LocalDate
Set<LocalDate> holidayDates = new HashSet<LocalDate>();
for(Holiday h : holidays){
        holidaysDates.add(h.getDate());
}
         
// create the HolidayCalendar ASSUMING that the set covers 2006!
final HolidayCalendar<LocalDate> calendar = new DefaultHolidayCalendar<LocalDate>
        (holidayDates, new LocalDate("2006-01-01"), new LocalDate("2006-12-31"));
           
// register the holidays, any calculator with name "UK"
// asked from now on will receive an IMMUTABLE reference to this calendar
LocalDateKitCalculatorsFactory.getDefaultInstance().registerHolidays("UK", calendar);
         
// ask for a LocalDate calculator for "UK"
// (even if a new set of holidays is registered, this one calculator is not affected
DateCalculator<LocalDate> cal = LocalDateKitCalculatorsFactory.getDefaultInstance()
        .getDateCalculator("UK", HolidayHandlerType.FORWARD);
                 
// set startDate, this will also set the current business date.
cal.setStartDate(new LocalDate("2006-08-28"));
         
// startDate stays 28 Aug 06 BUT the currentDate has moved,
// according to Forward handler to 29 Aug 2006.
LocalDate start = cal.getStartDate();   // 28 Aug 06
LocalDate current = cal.getCurrentBusinessDate(); // 29 Aug 06
 
LocalDate newCurrent = cal.moveByDays(4).getCurrentBusinessDate(); // 4 Sept 06 due to weekend!
         
// Example with Tenor, 1W with a 2 day spot lag
LocalDate date1WeekFromSpot = cal.moveByTenor(StandardTenor.T_1W, 2).getCurrentBusinessDate();