Long dayofmonth = floatingHoliday(new Long(2006),new Long(1),new Long(3),new Long(2),"Martin Luther King's Birthday");
public Long floatingHoliday(Long eventYear,Long eventMonth,Long weekNumber,Long dayOfWeek,String eventName) throws Exception {
// Floating holidays/events of the events.js file uses:
// the Month field for the Month (here it becomes the targetmo field)
// the Day field as the Cardinal Occurrence (here it becomes the cardinaloccurrence field)
// 1=1st, 2=2nd, 3=3rd, 4=4th, 5=5th, 6=6th occurrence of the day listed next
// the Year field as the Day of the week the event/holiday falls on (here it becomes the targetday field)
// 1=Sunday, 2=Monday, 3=Tuesday, 4=Wednesday, 5=Thurday, 6=Friday, 7=Saturday
// example: "F", "1", "3", "2", = Floating holiday in January on the 3rd Monday of that month.
//
// In our code below:
// targetyr is the active year
// targetmo is the active month (1-12)
// cardinaloccurrence is the xth occurrence of the targetday (1-6)
// targetday is the day of the week the floating holiday is on
// 0=Sun; 1=Mon; 2=Tue; 3=Wed; 4=Thu; 5=Fri; 6=Sat
// Note: subtract 1 from the targetday field if the info comes from the events.js file
//
// Note:
// If Memorial Day falls on the 22nd, 23rd, or 24th, then we add 7 to the dayofmonth to the result.
//
// Example: targetyr = 2052; targetmo = 5; cardinaloccurrence = 4; targetday = 1
// This is the same as saying our floating holiday in the year 2052, is during May, on the 4th Monday
//
Long dayofmonth = new Long(0); // zero out our TransitExceptions day variable.
Long dayOffset = new Long(0);
if(eventName.startsWith("Memorial") && eventMonth.equals(new Long("5")))
{ // Get last Monday of the month
Long lastdayInMay = new Long("31");
Date lastdate = new Date(eventMonth.toString()+"/"+ lastdayInMay.toString() +"/"+eventYear.toString()); // Object Storing the first day of the current month.
int lastday = lastdate.getDay() + 1; // The first day (1-7 = Sun-Sat) of the target month.
if(lastday == 2) // lastday is a Monday, leave as is...
{
dayofmonth = lastdayInMay;
} else if(lastday == 1) { // lastday is a Sunday...
dayofmonth = new Long(Math.round(lastdayInMay.longValue() - new Long("5").longValue()));
} else if(lastday > 2) { // lastday is a Tue-Sat...
dayOffset = new Long(Math.round(lastday - 2));
dayofmonth = new Long(Math.round(lastdayInMay.longValue() - dayOffset.longValue()));
}
} else {
Date firstdate = new Date(eventMonth.toString()+"/1/"+eventYear.toString()); // Object Storing the first day of the current month.
int firstday = firstdate.getDay() + 1; // The first day (1-7) of the target month.
if(dayOfWeek.intValue() >= firstday)
{
weekNumber = new Long(weekNumber.longValue() - 1);
}
dayofmonth = new Long(Math.round(Math.round(Math.round(dayOfWeek.intValue() - firstday)+1)+Math.round(weekNumber.longValue()*7)));
}
return dayofmonth;
}