Creating a Business Day Calculator

Hi there! first time poster -

I am trying to create a business day calculator that checks a table I created with relevant federal holidays and adjusts its business days accordingly.

I may be missing something very obvious but this is what i have so far and am actively working on its :sweat_smile:

{formdate: MM/DD/YYYY; name=start_date; default={time: MM/DD/YYYY}}
Days:{formtext: name=Business_Days_to_Add; default=5}
{formtoggle: name=business_days; default=yes}{endformtoggle}{formtoggle: name=calendar_days; default=yes}{endformtoggle}
{dbselect: SELECT Date, Name FROM FederalHolidays; space=xxxx; multiple=yes; menu=yes}
{currentDate={time: MM/DD/YYYY; at={=start_date}; pattern=MM/DD/YYYY}}
{businessDaysToAdd=business_days_to_add}
{addedDays=0}
{holidays=split(date, "")}

{if: business_days=yes}Business Days
{time: MM/DD/YYYY; shift={=businessdaystoadd}D(skip=SAT,SUN)}{endif}
{if: calendar_days=yes}Calendar Days
{time: MM/DD/YYYY; shift={=businessdaystoadd}D}{endif}

{if: business_days=yes}{repeat: business_days_to_add}{currentDate={time: MM/DD/YYYY; at={=currentdate}; pattern=MM/DD/YYYY}}{dayOfWeek={time: MM/DD/YYYY; at={=currentdate}; pattern=MM/DD/YYYY}}{isHoliday=includes(holidays, currentDate)}{endrepeat}{endif}

Hi!

Sorry for missing this when it was posted. Here is how you could do something like that.

I am defining a new function business_day_shift(start_date, days, holiday_list) that will calculate a day days away from start_date while skipping the weekends and any dates in the holiday_list.

Let me know if you have any questions.

{holidayList=["01/01/2025", "02/12/2025", "02/19/2025", "03/01/2025", "03/02/2025", "03/03/2025", "12/24/2025"]}
Date: {formdate: MM/DD/YYYY; name=selected_date}
Days: {formtext: name=days_to_add; default=6}
{business_day_shift=(start, days, holidays) -> block
# extra buffer if we encounter holidays
var BUFFER = 20
var daysToGet = days + buffer

var dates = [{time: MM/DD/YYYY; at={=start}; pattern=MM/DD/YYYY; shift={=d}D(skip=SAT,SUN)} for d in seq(1, daystoGet)]
dates = filter(dates, d -> not includes(holidays, d))

if count(dates) < days
# should never happen
error("Ran out of buffer, increase the buffer")
endif

return dates[days]
endblock}

business_day_shift(start, days, holidayList): {=business_day_shift(selected_date, days_to_add, holidayList)}

1 Like