get US Bank Holidays UDF

I was looking for an existing UDF on cflib.org for current bank holidays but the only one I could find was for German holidays only. With this function you can pass in a year otherwise it will assume the current year is to be used.

The following holidays are calculated using this UDF.

Holiday Official Date
New Year’s Day January 1
Independence Day July 4
Veterans Day November 11
Christmas Day December 25
Inauguration Day January 20th (Year after election year – multiple of 4)
MLK’s Birthday Third Monday in January
George Washington’s Birthday Third Monday in February
Memorial Day Last Monday in May
Labor Day First Monday in September
Columbus Day Second Monday in October
Thanksgiving Day Fourth Thursday in November

 

 

<cffunction name=”getUSBankHolidays” access=”public” output=”false” returntype=”struct” hint=”general bank holidays for US”>
<cfargument name=”iYear” default=”#Year(now())#” />

<cfset var currentYear = arguments.iYear />

<cfset var strResult =
{ NewYears = createDate(currentYear,1,1),
Independence = createDate(currentYear,7,4),
Veterans = createDate(currentYear,11,11),
Christmas = createDate(currentYear,12,25)
} />

<cfif NOT (currentYear – 1) MOD 4>
<cfset strResult.Inauguration = createDate(currentYear,1,20) />
</cfif>

<cfset strResult.MLKBirthday = createDate(currentYear,1,GetNthOccOfDayInMonth(3,2,1,currentYear)) />
<cfset strResult.WashingtonsBirthday = createDate(currentYear,2,GetNthOccOfDayInMonth(3,2,2,currentYear)) />
<cfset strResult.MemorialDay = createDate(currentYear,5,(DaysInMonth(createDate(2012,5,1))) – (DayOfWeek(createDate(2012,5,DaysInMonth(createDate(2012,5,1)))) – 2)) />
<cfset strResult.LaborDay = createDate(currentYear,9,GetNthOccOfDayInMonth(1,2,9,currentYear)) />
<cfset strResult.ColumbusDay = createDate(currentYear,10,GetNthOccOfDayInMonth(2,2,10,currentYear)) />
<cfset strResult.Thanksgiving = createDate(currentYear,11,GetNthOccOfDayInMonth(4,6,11,currentYear)) />

<cfreturn strResult />
</cffunction>

This function is long overdue for me as monitors that run on week days run on Holidays and result in a lot of false positive ‘down’ notifications. If the array returned is empty then the scheduled task should run. If the array has records then it’s a holiday

 

This UDF requires the getNthOccOfDayInMonth function from cflib.org