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>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson