/** * Show how to get a list of holiday dates using Jollyday(jollyday-0.4.3.jar) and Joda-Time(joda-time-1.6.2.jar). * You need Joda-Time library => https://www.joda.org/joda-time/. * You need Jollyday library => http://jollyday.sourceforge.net/. */ import de.jollyday.HolidayCalendar; import de.jollyday.HolidayManager; import de.jollyday.Holiday; import java.util.Collections; import java.util.Set; import java.util.ArrayList; public class Jollyday { public static void main(String[] args) { Jollyday oTest = new Jollyday(); // Print out all holiday dates of each year. for(int i=2008; i<=2011; i++) { ArrayList<String> lHolidays = oTest.getHolidays(i); for(String sHoliday: lHolidays) { System.out.print(sHoliday+" | "); } System.out.println(); } } /** * Get a list of holiday dates of a given year. * @param iYear * @return List of holiday dates of the whole year. */ public ArrayList<String> getHolidays(int iYear) { ArrayList<String> oSortedHolidays = new ArrayList<String>(); try { HolidayManager oManager = HolidayManager.getInstance(HolidayCalendar.CANADA); Set<Holiday> oHolidays = oManager.getHolidays(iYear, "qc"); // Quebec province for(Holiday oHoliday: oHolidays) { oSortedHolidays.add(oHoliday.toString()); } // Sorted holiday dates. Collections.sort(oSortedHolidays); } catch(Exception ex) { System.out.println(ex.getMessage()); } return oSortedHolidays; } }