Comparando períodos de calendário
Os períodos de calendário baseiam-se em unidades de tempo que incluem anos, meses, semanas, dias e o horário do dia. Por exemplo, é possível verificar se dois pontos no tempo estão no mesmo período de calendário ou se um evento ocorre em um determinado dia da semana ou horário do dia.
Use os operadores a seguir para comparar os períodos de calendário de dois pontos no tempo:
- is in the same calendar year as
Operadores semelhantes estão disponíveis para mês, semana e dia.
Por exemplo, 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
Operadores semelhantes também estão disponíveis para minutos e segundos.
- is before ou is after
Por exemplo, the calendar year of the departure time of 'the flight' is after the calendar year of the start of 'the business trip'.
- is during
Por exemplo, the scheduled departure time of 'the flight' is during the calendar year 2013.
- is during the same time as
Esse operador verifica se dois períodos começam no mesmo instante e terminam no mesmo instante. Por exemplo, the calendar year of the scheduled departure time of 'the flight' is during the same time as the calendar year 2013.
A regra a seguir verifica se o aeroporto está fechado no mesmo dia da partida do voo. Se a partida do voo for em 11 de fevereiro de 2014, a regra verificará se o evento de aeroporto fechado também ocorre em 11 de fevereiro de 2014.
when an airport closed event occurs
definições
set 'the flight' to a flight in the flights of 'the airport';
se
this airport closed event is on the same calendar day as the scheduled departure time of 'the flight'
então
print "The departure airport is closed on the day of the flight.";
A regra a seguir determina se o gasto diário durante os dias da viagem excede uma quantia especificada. As compras feitas durante o primeiro dia e o último dia da viagem não são consideradas:
definições
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'
e
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";
Dias da semana
A regra a seguir compara as compras feitas durante o fim de semana e as compras feitas durante a semana de trabalho:definições
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;
se
the total amount of 'weekend purchases' is more than the total amount of 'workweek purchases'
então
print "Spending is higher at weekends.";
A regra a seguir fornece uma promoção para compras feitas a bordo que ocorrem em uma terça-feira:
definições
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';
se
'purchase on board' is on Tuesday
então
print "apply special Tuesday discount for on-board purchases.";
Horário do dia
Um horário do dia é especificado em termos de horas, minutos e segundos em uma notação de tempo comum, por exemplo, 11:59:59 PM.
A regra a seguir compara o número de voos matutinos e o número de voos vespertinos durante os últimos seis meses:
definições
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;
se
the number of flights in 'morning flights' is more than the number of flights in 'afternoon flights'
então
print "more morning flights than afternoon flights.";