Duration operators
Use duration operators to define, calculate, and compare durations.
The following table lists the operators that you can use to specify and compare durations.
For more information about durations, see Reasoning over time and events.
Absolute durations
Operator | Example | Comments |
---|---|---|
the duration between <a date> and <a date> |
the duration between the launch date of 'the product' and the retirement date of 'the product' |
Returns an absolute duration. |
<an absolute duration> is longer than <an absolute duration> |
the duration of 'the business trip' is longer than the duration of 'the flight' |
|
<an absolute duration> is longer than or equal to <an absolute duration> |
the duration of 'the business trip' is longer than or equal to the duration of 'the flight' |
|
<an absolute duration> is shorter than <an absolute duration> |
the duration of 'the flight' is shorter than the duration of 'the business trip' |
|
<an absolute duration> is shorter than or equal to <an absolute duration> |
the duration of 'the business trip' is shorter than or equal to the duration of 'the flight' |
|
<an absolute duration> before <a date> |
the duration of 'the exceptional promotion' before the date of 'the purchase event' |
Returns a time point (date). |
<an absolute duration> after <a date> |
the duration of 'the business trip' after the arrival time of 'the flight' |
Returns a time point (date). |
<an absolute duration> in weeks |
the duration of 'the exceptional promotion' in weeks |
Converts a duration to a specific time unit (weeks). This operator returns an integer. The result is truncated. For example, if you are testing that the duration is 1 week, a duration of 11 days returns a positive result. To get the best result, you must choose the time unit that is closest to the result that you want to obtain. |
<an absolute duration> in days |
the duration of 'the business trip' in days |
Converts a duration to a specific time unit (days). This operator returns an integer. The result is truncated. For example, if you are testing that the duration is 1 week, a duration of 11 days returns a positive result. To get the best result, you must choose the time unit that is closest to the result that you want to obtain. |
<an absolute duration> in hours |
the duration of 'the flight' in hours |
Converts a duration to a specific time unit (hours). This operator returns an integer. The result is truncated. For example, if you are testing that the duration is 1 week, a duration of 11 days returns a positive result. To get the best result, you must choose the time unit that is closest to the result that you want to obtain. |
<an absolute duration> in minutes |
the duration of 'the flight' in minutes |
Converts a duration to a specific time unit (minutes). This operator returns an integer. The result is truncated. For example, if you are testing that the duration is 1 week, a duration of 11 days returns a positive result. To get the best result, you must choose the time unit that is closest to the result that you want to obtain. |
<an absolute duration> in seconds |
the duration of 'the flight' in seconds |
Converts a duration to a specific time unit (seconds). |
Calendar durations
To define a calendar duration in the rule, you replace the placeholder <calendar duration> with a number and a unit, or a combination of these. You can combine time units to form a new duration, for example, 1 year 6 months 3 days.
The time units can be years, months, weeks, days, hours, minutes, and seconds.
Operator | Example | Comment |
---|---|---|
<a calendar duration> before <a date> |
7 days before 'the purchase event' |
Returns a time point (date). Calendar durations are defined by a number and the name of the unit. The unit can be years, months, weeks, days, hours, minutes, and seconds. |
<a calendar duration> after <a date> |
4 hours 10 minutes after the arrival time of 'the flight' |
Returns a time point (date). Calendar durations are defined by a number and the name of the unit. The unit can be years, months, weeks, days, hours, minutes, and seconds. |
Example of calendar duration
The following rule uses a calendar duration of 1 hour and 30 minutes to check the delay of a flight departure.
when a flight departure event occurs
if
this flight departure event is after 1 hour 30 minutes after the scheduled departure time of 'the flight'
then
print "The departure of the flight is delayed by at least 1 and a half hour.";