Comparing calendar periods
Calendar periods are based on time units that include years, months, weeks, days, and the time of day. For example, you can check that two time points are in the same calendar period, or that an event happens on a certain day of the week, or time of the day.
Use the following operators to compare the calendar periods of two time points:
- is in the same calendar year
as
Similar operators are available for month, week, and day.
For example, the departure time of 'the flight' is in the same calendar month as the start of 'the business trip'
- is in the same hour as
Similar operators are also available for minutes and seconds.
- is before or is after
For example, the calendar year of the departure time of 'the flight' is after the calendar year of the start of 'the business trip'.
- is during
For example, the scheduled departure time of 'the flight' is during the calendar year 2013.
- is during the same time as
This operator checks that two time periods start at the same instant and end at the same instant. For example, the calendar year of the scheduled departure time of 'the flight' is during the same time as the calendar year 2013.
The following rule checks whether the airport is closed on the same day as the departure of the flight. If the flight departure is on February 11th, 2014, the rule checks that the airport closed event also happens on February 11th, 2014.
when an airport closed event occurs
definitions
set 'the flight' to a flight in the flights of 'the airport';
if
this airport closed event is on the same calendar day as the scheduled departure time of 'the flight'
then
print "The departure airport is closed on the day of the flight.";
The following rule determines whether the daily spending during the days of the trip exceeds a specified amount. Purchases during the first day and the last day of the trip are not taken into account:
definitions
set 'the trip' to a trip in the trips of 'the customer';
set 'on-trip purchases' to all purchase events where
the calendar day of each purchase event is after the start of 'the trip'
and
the calendar day of each purchase event is before the end of 'the trip';
if the total amount of 'on-trip purchases'/
the duration between the start of 'the trip' and the end of 'the trip' in days
is more than 1000
then print "Average spending per day is high";
Day of week
The following compares shopping during the weekend and shopping during the work week:definitions
set 'purchases last 6 months' to all purchase events
where each purchase event is during the last period of 6 months;
set 'workweek purchases' to all purchase events in 'purchases last 6 months'
where the day of week of each purchase event is after or the same as Monday
and the day of week of each purchase event is before or the same as Friday;
set 'weekend purchases' to all purchase events in 'purchases last 6 months'
where the day of week of each purchase event is before Monday
and the day of week of each purchase event is after Friday;
if
the total amount of 'weekend purchases' is more than the total amount of 'workweek purchases'
then
print "Spending is higher at weekends.";
The following rule gives a promotion to on-board purchases that happen on a Tuesday:
definitions
set 'the flight' to a flight in the flights of 'the customer';
set 'the flight period' to the period between the scheduled departure time of 'the flight' and the scheduled arrival time of 'the flight';
set 'purchase on board' to a purchase event
where this purchase event is during 'the flight period';
if
'purchase on board' is on Tuesday
then
print "apply special Tuesday discount for on-board purchases.";
Time of day
A time of day is specified in terms of hours, minutes, and seconds in a usual time notation, for example, 11:59:59 PM.
The following rule compares the number of morning flights and the number of afternoon flights during the last six months:
definitions
set 'flights last six months' to all flights in the flights of 'the customer'
where the scheduled departure time of each flight is during the last period of 6 months;
set 'morning flights' to all flights in 'flights last six months'
where the time of day of the scheduled departure time of each flight is before 12:00:00 PM;
set 'afternoon flights' to all flights in 'flights last six months'
where the time of day of the scheduled departure time of each flight is after or the same as 12:00:00 PM;
if
the number of flights in 'morning flights' is more than the number of flights in 'afternoon flights'
then
print "more morning flights than afternoon flights.";