mrbusche.com

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.

HolidayOfficial Date
New Year's DayJanuary 1
Independence DayJuly 4
Veterans DayNovember 11
Christmas DayDecember 25
Inauguration DayJanuary 20th (Year after election year – multiple of 4)
MLK's BirthdayThird Monday in January
George Washington's BirthdayThird Monday in February
Memorial DayLast Monday in May
Labor DayFirst Monday in September
Columbus DaySecond Monday in October
Thanksgiving DayFourth 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))) &#8211; (DayOfWeek(createDate(2012, 5, DaysInMonth(createDate(2012, 5, 1)))) &#8211; 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