Holiday Times

Certain business processes may change depending on whether it is in working hours or not, such as whether to transfer a call or take a message. For example, if a company has 09:00-17:00 business hours, their script may change contents if a caller tries to contact them at 20:00.

This process would usually be broken down into three elements:

1. Check the day

2. Check the time

3. Check if it's a holiday

Example

The first step is to check if the current time and date fall within your working hours. This can be done using a Calculate control, below is an example of JavaScript code that can be used:
if ([var_inOfficeHours] === '') {
  var today     = new Date();       // Get today's date
  var dayNumber = today.getDay();   // Get the numeric day of the week (0-6)
  var hour      = today.getHours(); // Get the current hour

  [var_inOfficeHours] = 'No'; // [var_inOffice] defaults to No

  // If the day of the week is between Monday and Friday (Article)
  if (dayNumber >= 1 && dayNumber <= 5) {
    // If the current time is between 09:00-17:00
    if (hour >= 9 && hour <= 17) {
      // Check holiday database against current time
      Script.Utils.GetCSObject([Check Holidays]).click(); // (Article)
    }
}
Instead of storing a list of holidays in each Workflow, a list of holidays is often stored in a SQL table, allowing easier management across all Workflows. In this example, the final part of the code above triggers an External Data Source control called [Check Holidays] that performs a lookup against a table like this.
 
In this example, the SQL query below is used inside of the [Check Holidays] External Data Source:
-- Set the date format
SET DATEFORMAT DMY

-- Check if today's date equals any date in the Holidays table
IF EXISTS (
    SELECT *
    FROM Holidays
    WHERE HolidayDates = CONVERT(DATE, GETDATE())
)
BEGIN
    -- Set [var_inOfficeHours] to 'No'
    SELECT 'No' AS Result
END
ELSE
BEGIN
    -- Set [var_inOfficeHours] to 'Yes'
    SELECT 'Yes' AS Result
END
Once the SQL query has been written and you press Next, you will be presented with a Column Mapping page that allows the results of the SQL query to be mapped to the variable [var_inOfficeHours]. To set up the mapping, set the column to Result and the Fields/Variables to [var_inOfficeHours].

Summary

By following the code above, you will end up with a variable called [var_inOfficeHours] which will either be Yes or No depending on the current day of the week, the time of day, and whether today was listed as a holiday in a table called Holidays.