Working with durations

A duration is the distance between two time points. A duration can be represented by the distance between two points, or it can be defined by a number and a unit, such as six months.

Durations include absolute durations or calendar durations.

Absolute durations

Absolute durations measure the distance between two time points. Absolute durations can be expressed in different ways:
  • The duration that is computed for two given time points: the duration between <a date> and <a date>.

    For example, the duration between the departure time of 'the flight' and the arrival time of 'the flight'

  • The duration of a time period: the duration of <a time period>.

    For example, the duration of 'the flight period'

  • The duration as an attribute of an object, for example the planned duration of 'the flight'

    In the business model definition, you can set the type (duration) to an event or entity attribute. For example, in the .bmd file you write the following statement for a flight entity: a flight has a planned duration (duration).

An absolute duration can be converted into a specific time unit: the planned duration of 'the flight' in hours. This operation returns an integer. These conversions do not include years and months as they are irregular time units.

The following rule checks if the duration of the flight is longer than expected.

when a flight arrival event occurs
definitions
    set 'the flight departure event' to a flight departure event;
    set 'the actual duration' to the duration between 'the flight departure event' and this flight arrival event;
if
    'the actual duration' is longer than the planned duration of 'the flight'
then
    print "The duration of the flight is longer than expected";

Calendar durations

Calendar durations are expressed by units of time. The units can be years, months, weeks, days, hours, minutes, and seconds.

In a rule, you replace the placeholder <calendar duration> with a number and the name of the unit, or a combination of these.

  • A number and the name of the unit, for example, 5 days before 'the flight departure event'.
  • A combination of numbers and time units, for example 1 week 5 days 2 hours before 'the flight departure event'

    Durations over different units are combined to form a new duration. These units are ordered and processed in decreasing order. For example, 1 year 1 month 1 day or 7 days 3 hours.

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 was delayed by at least an hour and a half.";