CFLib.org – Common Function Library Project

getBankHolidays([iYear])

Last updated March 13, 2011

author

Sigi Heckl

Version: 0 | Requires: CF5 | Library: CFMLLib

Description:
Returns a struct with the bank holidays of Germany. I am sure you can adapt this to your local given holidays. The essential part of the function is the easter formula.

Return Values:
Returns a struct

Example:

<cfdump var="#getBankHolidays()#">

Parameters:

Name Description Required
iYear Defaults to current year No

Full UDF Source:

<!---
 Returns a struct with the bank holidays of Germany
 
 @param iYear      Defaults to current year (Optional)
 @return Returns a struct 
 @author Sigi Heckl (siegfried.heckl@siemens.com) 
 @version 0, March 13, 2011 
--->
<cffunction name="getBankHolidays" access="public" output="false" returntype="struct" hint="general bank holidays for DE">
  <cfargument name="iYear" type="numeric" default="#datepart('yyyy',now())#" hint="year for calculation" />

    //definition of constant holidays
    <cfset var strResult = {newyear     = createDate(arguments.iYear,1,1),
                            dayOfWork   = createDate(arguments.iYear,5,1),
                            christmas1  = createDate(arguments.iYear,12,25),
                            christmas2  = createDate(arguments.iYear,12,26),
                            nationalDay = createDate(arguments.iYear,10,3)
                           } />
    <cfset var local     = {} />

    //easter formula to get variable holidays
    <cfset local.k  = round(arguments.iYear / 100) />
    <cfset local.m  = 15 + round((3*local.k +3)/4) - round((8*local.k+13)/25) />
    <cfset local.s  = 2 - round((3*local.k+3)/4) />
    <cfset local.a  = arguments.iYear mod 19 />
    <cfset local.d  = (19*local.a+local.m) mod 30 />
    <cfset local.r  = round((local.d + round(local.a/11))/29) />
    <cfset local.og = 21 + local.d - local.r />
    <cfset local.sz = 7 - (arguments.iYear + round(arguments.iYear/4) + local.s) mod 7 />
    <cfset local.oe = 7 - (local.og-local.sz) mod 7 />
    <cfset local.os = local.og + local.oe />
    <cfset local.om = 3 />
    <cfif local.os GT 31>
      <cfset local.os = local.os - 31 />
      <cfset local.om = 4 />
    </cfif>

    <cfset local.easterSunday    = createDate(arguments.iYear, local.om, local.os) />
    <cfset strResult.osterMonday = dateAdd('d',1,local.easterSunday) />
    <cfset strResult.goodFriday  = dateAdd('d',-2,local.easterSunday) />
    <cfset strResult.whitsun     = dateAdd('d',50,local.easterSunday) />
    <cfset strResult.ascension   = dateAdd('d',39,local.easterSunday) />

    <CFRETURN strResult />
</cffunction>

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson