Working with the current time

The current time represents the most recent point in time. Expressions of the current time include, for example, the current month, the last or next 3 hours, now, today, tomorrow, and yesterday.

The current time can be expressed in the following ways.

Now

In the rule language, the current time is a time point that is expressed with the term now. The value of now for operations in the business language is precise to seconds. If an event is delayed in transit, the event might have an earlier time stamp than the value of now.

The following rule sends a reminder each Monday at 10:00 AM:

if 
 now is on Monday at 10:00:00 AM
then 
	 print "send weekly reminder.";

Now is set from the time stamp of the event, which is truncated to the second. However, if events arrive out of order, now never moves backwards in time. For example, if an event arrives with a time stamp of today at 11:00:00 AM, followed by another event with a time stamp of today at 10:55:00 AM, now is 11:00:00 AM when both events are processed. If necessary, a rule can detect that an event was delayed in transit by checking whether the time stamp of the event is before now.

When a rule must be evaluated at a particular time, the rule is processed as closely to that time as possible. For example:
 if
  now is on Monday at 10:00:00 AM
This rule is processed as closely as possible to 10:00:00 AM each Monday, and now is set to exactly 10:00:00 AM when that rule is processed.

Current periods

To refer to a period in a time scale that contains the current time, a rule can use expressions such as the current year and the current month. These expressions are equivalent to the calendar year of now, and the calendar month of now.

The following rule checks for closed airports during this month:

when an airport closed event occurs
if
    the number of airport closed events during the current month is more than 4
then
    print “More than 4 airports have been closed this month.”;
Warning: If you use expressions that refer explicitly or implicitly to now, such as the current month or the last period of , you must be aware that now might not refer to the time stamp of the event in the when <event> occurs clause. For more information, see Event processing in agents.

Last and next periods

To refer to a period that precedes or follows the current time, use the last period of and the next period of operators. Both expressions refer to the current time now, but they do not include it.

the last period of 7 days corresponds to the period of 7 days before now.

The following rule sends a warning if there were five or more delayed flights in the last three months. The flight delayed event that is processed in the when clause is not included in the count because it is not included in the period. The condition of the rule becomes true when the sixth event is received.

when a flight delayed event occurs
if
    the number of flight delayed events during the last period of 3 months is at least 5
then
    print "Warning: the number of delayed flights in the past 3 months is at least 5." ;

The following rule checks if other flights are planned in the next half hour after a delayed flight event:

when a flight arrival event occurs 
if
 there is at least one flight in the flights of 'the customer' 
	where the scheduled departure time of this flight is during the next period of 30 minutes, 
then 
	print "The customer has less than 30 minutes to get to the next flight.";

Yesterday, today, tomorrow

today, tomorrow, and yesterday are time periods of one day. These periods are calendar days, which means that they start and end at midnight.
  • today corresponds to the expression the calendar day of now.
  • yesterday corresponds to the period of one day before today.
  • tomorrow corresponds to the period of one day after today.

The following rule checks for overnight flights:

if
    the scheduled departure time of 'the flight' is during yesterday
    and the scheduled arrival time of 'the flight' is during today
then
    print "Overnight flight." ;