Working with time periods

A time period is an interval of time which is defined by a start time and an end time. A period has a duration, which is equal to the distance between its start and end times. Periods include the start time point, but not the end time point.

You can specify a time period by a start time and an end time, a start time and a duration, or an end time and a duration. Time periods are also obtained when converting a time point into a larger time scale. In that case, the time period is specified by a time point and a target unit.

Time periods can be expressed in different ways.

Calendar periods

Calendar periods include calendar years, months, and days.
  • A year period is specified by the term calendar year and the number of the year, for example the calendar year 2011.
  • A month period is specified by the name of the month and the number of the year, for example the calendar month February 2014.
  • A day period is specified using a standard date notation, for example the calendar day December 31, 2013.

    In this example, the period of one day starts at 12/31/1999 00:00:00 AM and ends at 1/1/2000 00:00:00 AM .

The following rule checks whether an airport has been closed during December 31st, 2013. This rule is evaluated at the end of December 31st, 2013.

if
    there is at least one airport closed event
        where this airport closed event is during the calendar day December 31, 2013 ,
then
    print "The airport was closed on the last day of the year 2013.";

Periods with start and end points

Time periods can be specified by a start time point and an end time point. For example, the period between the start of 'the business trip' and the end of 'the business trip'.

The following rule checks if there are more than 10 purchases during the flight. The rule defines the flight period as the period between the departure and the arrival of the flight.

definitions
    set 'the flight period' to the period between the scheduled departure time of 'the flight' and the scheduled arrival time of 'the flight';
if
    there are more than 10 purchase events
        where each purchase event is during 'the flight period',
then
    print "More than 10 purchases during this flight.";

Periods with start or end points, and a duration

Time periods can be specified by a start or end time, and a duration. For example, the period of 7 days before 'the purchase event'.

Use the following operators to define a period that starts or ends at a specified time, and has a certain duration.
  • before and after define the start or end time of the time period. They are used to refer to a time period that succeeds or precedes a given time point, and that does not include this time point.

    For example, the period of 3 months before May 2012.

  • the period of <calendar duration> before defines a period of a given duration that ends at a given time.
  • the period of <calendar duration> after defines a period of a given duration that starts at a given time. For example, the period of 4 hours after the 'the flight' arrived

Use the following operators to define a period that starts or ends at a specified time, that has a certain duration, and that includes the specified time point:

  • the period of <calendar duration> starting at <a date> defines a period of a given duration that starts at a given time.
  • the period of <calendar duration> ending at <a date> defines a period of a given duration that ends at a given time. For example, the period of 4 hours ending at 'the purchase event'.

The following rule checks whether there was a purchase event in the 3 hours after the arrival of the flight.

when a flight arrival event has occurred 1 day ago
if
    there is at least one purchase event
        where this purchase event is during the period of 3 hours after this flight arrival event,
then
    print "At least one purchase 3 hours after the arrival of the flight.";

Periods can be specified by a calendar duration over multiple time units. For example, the period of 2 months 2 weeks after the launch date of 'the product'. If the product is launched on February 14th, 2013 9:00:00 AM, then the period of two months and two weeks ends on April 28th, 2013 9:00:00 AM.

Time points converted to a period

Time periods can be obtained by converting a time point into a larger time scale. For example, the period of 7 days before the calendar day of 'the purchase event'. In this example, the calendar day refers to the day in the Gregorian calendar that contains the time point 'the purchase event'.