Created
March 23, 2025 19:16
-
-
Save trycf/6416ffecb9f2e710a2918cbe0cc575a4 to your computer and use it in GitHub Desktop.
TryCF Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cffunction name="businessDaysBetween" returntype="numeric" access="public"> | |
<!--- // Your code goes here ---> | |
</cffunction> | |
<!--- Define UK Holidays for 2024 ---> | |
<cfset ukHolidays = [ | |
<!--- 2024 UK Bank Holidays ---> | |
createDate(2024, 1, 1), <!--- New Year's Day ---> | |
createDate(2024, 3, 29), <!--- Good Friday ---> | |
createDate(2024, 4, 1), <!--- Easter Monday ---> | |
createDate(2024, 5, 6), <!--- Early May Bank Holiday ---> | |
createDate(2024, 5, 27), <!--- Spring Bank Holiday ---> | |
createDate(2024, 8, 26), <!--- Summer Bank Holiday ---> | |
createDate(2024, 12, 25), <!--- Christmas Day ---> | |
createDate(2024, 12, 26) <!--- Boxing Day ---> | |
]> | |
<cfset startDate = createDate(2024, 1, 1)> | |
<cfset endDate = createDate(2024, 12, 31)> | |
<cfset businessDays = 254> | |
<cfoutput> | |
<h2>Business Days Calculation</h2> | |
<p>Start Date: #dateFormat(startDate, "yyyy-mm-dd")#</p> | |
<p>End Date: #dateFormat(endDate, "yyyy-mm-dd")#</p> | |
<p>Total Business Days: #businessDays#</p> | |
<h3>UK Holidays Excluded:</h3> | |
<ul> | |
<cfloop array="#ukHolidays#" index="holiday"> | |
<li>#dateFormat(holiday, "yyyy-mm-dd")# - #getHolidayName(holiday)#</li> | |
</cfloop> | |
</ul> | |
</cfoutput> | |
<!--- Helper function to get holiday names, needs to be fixed ---> | |
<cffunction name="getHolidayName" returntype="string"> | |
<cfargument name="holidayDate" type="date" required="true"> | |
<cfset var dateStr = dateFormat(arguments.holidayDate, "yyyy-mm-dd")> | |
<cfset var holidayNames = { | |
"2024-01-01": "New Year's Day", | |
"2024-03-29": "Good Friday", | |
"2024-04-01": "Easter Monday", | |
"2024-05-06": "Early May Bank Holiday", | |
"2024-05-27": "Spring Bank Holiday", | |
"2024-08-26": "Summer Bank Holiday", | |
"2024-12-25": "Christmas Day", | |
"2024-12-26": "Boxing Day" | |
}> | |
<cfreturn "Unknown Holiday"> | |
</cffunction> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment