ACF Library

NonBusinessHolidays

Back to List

Description: Calculate number of holidays that fell on regular working days between two dates.

FileMaker Prototype:

Set Variable [$res; ACF_Run("NonBusinessHolidays"; int_Year;  date_dateFrom;  date_dateTo;  bool_saturdays)]

Category: UTILITY

Dependencies

Function source:

function NonBusinessHolidays ( int Year, date dateFrom, date dateTo, bool saturdays)
   JSON holidays; 
   holidays["a"] = NorwegianHolidaysENJS(Year); 
   
   date holidaydate; 
   int dow; 
   int result,i,j = sizeof (holidays["a"]); 
   
   for (i=1,j)
      holidaydate = date (holidays["a["+i+"].date"],"%Y-%m-%d");
      print ( "Holiday:"+ holidaydate+"\n");
      if (holidaydate>=dateFrom &&  holidaydate<=dateTo)  then
         dow = string(holidaydate,"%w"); 
         dow = ((dow==0)?7:dow); 
         // Add one in case of holday on normal working day. 
         if ( saturdays ) then
            result += ((dow>6)?0:1); 
         else
            result += ((dow>5)?0:1); 
         end if
      end if
   end for
   print "Holidays on MON-FRE (SAT) in year: " + Year + ": " + result + "\n"; 
   return result;
end

The NonBusinessHolidays Function calculates the number of holidays that occur on regular workdays within a date interval. The date interval has to be in the same year as supplied in the year parameter. For date intervals that cross the year boundary, you need to call this function for subintervals for each year. The saturday parameter means that we count saturdays as normal working days.

It is used by the function BusinessDays

Dependencies

Dependencies must be located before they are used.

  • NorwegianHolidaysENJS

Example

Set Variable [$res; ACF_Run("NonBusinessHolidays"; 2020; "01/01/2020";  "16/01/2020";  0)]

This result in 1 holiday, namely the New Year's Day that occur on Wednesday.

Year crossing date interval

The following ACF snippet, can be used to count the NonBusinessHolidays for more than one year.

// Holydays
function NonBusinessHolidaysYearCrossing ( date from, date to, bool saturdays)
    int result = 0; 
        int YearStart = string(from, "%Y"); 
        int YearEnd = string(to, "%Y"); 
        date dyStart, dyEnd; 
        for (i = YearStart, YearEnd)
            dyStart = ((i==YearStart)?from:date(format("%Y-01-01", i), "%Y-%m-%d"));
            dyEnd = ((i==YearEnd)?to:date(format("%Y-12-31", i), "%Y-%m-%d"));
            result += NonBusinessHolidays ( i ,dyStart, dyEnd, saturdays); 
        end for
        return result; 
    end

Calling this function looks like this:

Set Variable [$res; ACF_Run("NonBusinessHolidaysYearCrossing"; "01/05/2020";  "16/01/2024";  0)]

This will loop through the years from 2020 to 2024:

  • 2020: date interval 01/05/2020 - 31/12/2020
  • 2021: date interval 01/01/2021 - 31/12/2021
  • 2022: date interval 01/01/2022 - 31/12/2022
  • 2023: date interval 01/01/2023 - 31/12/2023
  • 2024: date interval 01/01/2024 - 16/01/2024
Back to List