Determine the next working day when given a date
- Last Updated: April 30, 2021
- 4 minute read
- Corticon
- Version 7.2
- Documentation
Problem
For any given date, determine the next working day. Take into consideration weekends and holidays.
Solution
Implemented correctly in Corticon Studio, these rules should start with a given input date, and increment as necessary until the next workday is identified (workday is defined here as any day not Saturday, Sunday, or a national holiday). A simple Vocabulary that supports these rules is shown in Example of a finite single-rule loop.
Next, the rules are implemented in the Rulesheet shown in the following figure:
- Notice that the Scope section is not used. A very simple Vocabulary is used with short entity names and no associations, so aliases are not necessary. Furthermore, none of the rules use collection operations, so aliases representing collections are not required either.
- The first rule executed is the nonconditional equation (in
column 0) setting
nextWorkDayequal tocurrentDateplus one day. - Rule 1 (in column 1) checks to see if the DateTime of the
nextWorkDaymatches any of the holidays defined in one or moreHolidayentities. If it does, then the Action row B incrementsnextWorkDayby one day and posts a warning message. - Rule 3 checks to see if the
nextWorkDayfalls on a Sunday. Notice that this rule uses the.dayOfWeekoperator, which is described in full detail in the Rule Language Guide. If the day of the week is Sunday (in other words,.dayOfWeekreturns a value of1), then the Action incrementsnextWorkDayby one day and posts a warning message. - Rule 4 checks to see if the
nextWorkDayfalls on a Saturday. If the day of the week is Saturday (in other words,.dayOfWeekreturns a value of7), then the Action row C incrementsnextWorkDayby two days and posts a warning message. By incrementing 2 days, an extra iteration is skipped because we know Sunday is also a non-workday.
Do not forget to check for conflicts: they exist in this Rulesheet. Assume that a holiday never falls on a weekend.
A modified Rulesheet displays the overrides added to resolve the conflicts in the following figure:
Using the same rules as before, click the Logical Loop Checker
icon in the Corticon Studio toolbar. The following window
opens:
This window first identifies which rules are involved in loops. The window also outlines the specific attribute interactions that create the loops.
Now that you understand the looping logic in your Rulesheet, create a Ruletest to verify that the loops operate as intended and produce the correct business results.
Given that July 4th, 2025 falls on a Friday, you
expect nextWorkDay to contain a final value of July
7th, 2025, a Monday, when the loops terminate. When the
Ruletest runs, you see the following:
As you can see, the result is a three-day weekend!