NOTE: Screen shots are from version 4.3

Best Practices

But generally I think doing the calculation inline is the simplest:


However if you need to test the calculated age in several places or do a calculation with it (or if you want to display it in a rule statement or return the value to the calling application) then this is probably better:

Where age is either transient (if you don’t need to return it to the calling application) or base (if you do)

You can also put explicit dates in the condition entries:



Do the data calculation directly in the rulesheet condition



Use a non-conditional rule to create a temporary variable that contains the duration of interest

Use a Calendar business entity to hold all the dates and durations of interest


This could also be calculated. Though Easter is rather complex:

If we confine ourselves to the years 1900-2099 and consider only the Gregorian calendar, the following formula may be used:

H = (24 + 19*(year mod 19)) mod 30

I = H - H/28

J = (year + year/4 + I - 13) mod 7

L = I - J

EasterMonth = 3 + (L + 40)/44

EasterDay = L + 28 - 31*(EasterMonth/4)

(Again, the divisions are integer divisions, in which remainders are discarded.)





Some Sample Date Calculations

How to find the most recent date in a collection of dates


The alias event simultaneously refers to both the entire collection of events and the one we are currently processing. So when the current event is the first event (when sorted in descending order by date) then we have the most recent event.

Note: This may not be the most efficient implementation since the sorting is going to occur for every event  processed so it may be better to model it this way:


So the most recent date is only extracted once and sorting is only done once.

But the difference in speed only begins to show up when you have more than 1000 events

NOTE: The following expression, although it looks reasonable, will not work:

patient.mostRecentDate =>max


Leap Year Determination

Last Day of the Month (or number of days in the month)


How to Advance N days from a given date skipping over weekends and identified holidays

This setup sheet precedes the main sheet

The following  sheet needs to be set to iterative:



Holidays may be defined in a rulesheet or retrieved from a database or even calculated based on rules:

As rules:

* New Year's Day, January 1st.

* Birthday of Martin Luther King, third Monday in January.

* Inauguration Day, January 20th every four years, starting in 1937.

* Washington's Birthday, third Monday in February since 1971; prior to that year, it was celebrated on the traditional date of February 22.

* Inauguration Day, March 4th every four years, pre-1937.

* Armed Forces Day, third Saturday in May.

* Memorial Day, last Monday in May since 1971; from 1868 to 1970 it was celebrated on May 30, and was called Decoration Day for part of that time.

* Flag Day, June 14th.

* United States of America's Independence Day, July 4.

* Labor Day, first Monday in September.

* Columbus Day, second Monday in October (federal holiday since 1971).

* Election Day, Tuesday on or after November 2.

* Veterans Day, November 11th (except from 1971 to 1977, inclusive, when it was celebrated on the fourth Monday in October; formerly known as Armistice).

* Thanksgiving Day, fourth Thursday in November.

* Christmas Day, December 25th. I have finally included this since it is a federal holiday, although it is not based on a secular holiday.

* Groundhog Day, February 2.

* Lincoln's Birthday, February 12.

* Valentine's Day, February 14.

* Washington's Birthday, February 22.

* St. Patrick's Day, March 17.

* April Fools's Day, April 1.

* Earth Day, April 22 (since 1970; see

* Administrative Assistants' Day, which once upon a time was Secretaries' Day, is the Wednesday of the last full week of April (that is, the Wednesday before the last Saturday in April) since 1955; see this site for more information.

* Arbor Day is often the last Friday in April (since 1872), but since planting conditions vary, it may occur from September to May; please consult the National Arbor Day Foundation's list of Arbor Day Dates.

* Mothers' Day, second Sunday in May (36 USC Sec. 142).

* Fathers' Day, third Sunday in June (36 USC Sec. 142a).

* Parents' Day, fourth Sunday in July (36 USC Sec. 142c).

* Grandparents' Day, Sunday after Labor Day (36 USC Sec. 142b).

* Columbus Day (traditional), October 12.

* United Nations Day, October 24.

* Halloween, October 31.

How to Find Gaps in a Series of Intervals


How to Find Overlaps in a Series of Intervals

In this example we want to see if any part-time employment coincides with any full time employment


Details of actions 2..5:


Adjusting Dates Automatically in test data

There’s no way to automatically adjust the dates in a test case.

Unfortunately the find/replace function is not available there (seems like it should be though)

However here are some alternatives:

Method 1 – edit the export file

You can export your test data to an XML file

And then open that file – then you can do a find/replace – and then import that file to create a new test case

Method 2 – use a rulesheet to adjust the dates

You could keep the test case fixed, but add a rulesheet that adjusts all (or some of) the dates by a certain amount.

The amount of the adjustment could be supplied as another piece of input data.

That way if the adjustment value is not supplied (as would be the case in production) then the input dates would be used as is.