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.

Figure 1. Sample Vocabulary for holiday rules

Next, the rules are implemented in the Rulesheet shown in the following figure:

Figure 2. Sample Rulesheet for Determining Next Workday
To step through this Rulesheet:
  1. 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.
  2. The first rule executed is the nonconditional equation (in column 0) setting nextWorkDay equal to currentDate plus one day.
  3. Rule 1 (in column 1) checks to see if the DateTime of the nextWorkDay matches any of the holidays defined in one or more Holiday entities. If it does, then the Action row B increments nextWorkDay by one day and posts a warning message.
  4. Rule 3 checks to see if the nextWorkDay falls on a Sunday. Notice that this rule uses the .dayOfWeek operator, which is described in full detail in the Rule Language Guide. If the day of the week is Sunday (in other words, .dayOfWeek returns a value of 1), then the Action increments nextWorkDay by one day and posts a warning message.
  5. Rule 4 checks to see if the nextWorkDay falls on a Saturday. If the day of the week is Saturday (in other words, .dayOfWeek returns a value of 7), then the Action row C increments nextWorkDay by 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. 

Note: Resolution of the conflicts is straightforward, so that is not addressed in detail here. One conflict – that between rules 1 and 4 - is left unresolved because the assumption is that a holiday never falls on a weekend. See Logical Analysis chapter more a complete discussion of conflict and other logical problems.

A modified Rulesheet displays the overrides added to resolve the conflicts in the following figure:

Figure 3. Holiday rules with ambiguities resolved by overrides

Using the same rules as before, click the Logical Loop Checker icon in the Corticon Studio toolbar. The following window opens:

Figure 4. Results of Logical Loop Check

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.

Figure 5. Ruletest for holiday rules

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:

Figure 6. Ruletest output for holiday rules

As you can see, the result is a three-day weekend!