Interval

Class INTERVAL [G -> ABSOLUTE] deals with intervals between two instances of the same class (an actual generic parameter substituting for G) which conforms to ABSOLUTE (specifically: DATE, TIME, DATE_TIME).

Creation

The creation procedure make (s, e: G) takes as arguments two instances of type G (or G's actual type from a declaration, e.g., my_time_interval: INTERVAL [TIME] ), which will become the start bound and the end bound of the INTERVAL. The start bound argument must be "before" the end bound argument (i.e., s <= e). make creates twins of its arguments so that the objects referenced as arguments will not change even if the values in the INTERVAL change.

Interval measurement

The measurement of an interval is done by applying the query duration. Although the result of duration will be an instance of class DURATION, it will be a direct instance of the DURATION descendant that is appropriate to the actual value of the generic parameter G. So, for an INTERVAL [TIME], the result of duration will be a direct instance of TIME_DURATION.

Comparison

  • infix < and infix > compare two intervals on a "strict" basis. This means that int_1 < int_2 is True if int_1 starts and ends strictly before int_2. In other words, int_1 must have a start bound less than that of int_2 and an end bound less than that of int_2.
  • infix <= and infix >= compare two intervals on a non-strict basis. So, int_1 <= int_2 is True if int_1 has a start bound less than or equal to that of int_2 and an end bound less than or equal to that of int_2.
  • is_equal (or ~)performs object comparison.
  • intersects is true if one (target) INTERVAL shares some of the same bounded area with a second (argument) INTERVAL.
  • overlaps is similar to intersects with the exception that the argument INTERVAL has to be after the target INTERVAL. is_overlapped is the opposite of overlaps.
  • meets and is_met are used to test whether two intervals have a common bound.
  • strict_includes can be used to test whether the target INTERVAL strictly includes the argument INTERVAL. So, int_1.strict_includes (int_2) will be True if the start bound of int_2 is greater than the start bound of int_1 and the end bound of int_2 is less than the end bound of int_1. is_strict_included_by provides the opposite of strict_includes.
  • includes and is_included_by test for inclusion on a non-strict basis.

Status Report

  • empty is True if the INTERVAL is empty, i.e., if the value of the start bound is equal to the value of the end bound.
  • has, strict_before, strict_after, before, and after test the position of an element relative to the current interval.

Element change

set_start_bound and set_end_bound are available to change the bounds. set_start_bound and set_end_bound create new objects from their arguments (twins), so that if these bounds are altered later, the original objects which had been referenced as arguments will not change.

Operations

  • union provides a new INTERVAL that includes the entire range covered by both the target INTERVAL and an argument INTERVAL which intersects the target.
  • intersection returns a new INTERVAL that represents the area common to both the target INTERVAL and the argument INTERVAL. intersection returns Void if the target and argument do not intersect.
  • gather requires that a target and argument INTERVAL have a common bound (i.e., int_1.meets (int_2) is True) and then returns a new INTERVAL with the union of the two.