Intervals

An interval typically consists of all time elements between two boundaries. For example all elements between 15 and 20.

Interval definitions

Closed intervals

We call it al closed interval if we consider the boundaries to belong to the interval. We will write this with square brackets: [begin:end]. For example a closed interval [15:20] based on N (natural numbers) is the set 15, 16, 17 ,18, 19, 20 .

Open intervals

If the boundaries are not considered part of the interval then it is an open interval. The notation is with round brackets: (begin:end).

For example an open interval (15:20) in N is the same as 16,17,18 19 and [16:19].

Half open intervals

Combinations are possible. A right open interval notation [begin:end) does not include the upper boundary and a left open interval (begin:end] is the opposite.

Examples: [15:20) is 15, 16, 17 ,18, 19 . (15:20] is 16, 17, 18, 19, 20 .

Unit intervals

An closed interval where the upper and lower boundaries are the same has exactly one member.

For example [15:15] is the set 15 .

Infinite intervals

In mathematics sometimes the notation [x, ? ) is used to mean all elements greater or equal then x. This interval has an infinite length if based on mathematical sets such as Q or R or even N. Similar with ( ?,x].

Time intervals

The above definitions can also be applied to time. It is always important to understand what the underlying time unit is. For example if we work with dates:

Temporalizing data with intervals

Non-temporal form

Databases and domain models describe the state of affairs in the real world. For example (Frank, Baarn) would typically mean that Frank lives in Baarn at the current moment. If we want to add a time dimension to this than there are two formats.

Since form

Frank lives in Baarn since 8-aug-2006. This means that Frank lives in Baarn since 8-aug-2006 up till now. However the current date is constantly moving. So we just donot bother to store an enddate. If we would the database would be busy just keeping dates. Sometimes infinite intervals can be (mis)used for the purpose of recording the current situation. The database would record that Frank lives in Baarn in the interval [8-aug-2006:EOT]. And we have to interpret EOT as unknown date in the future. The advantage of this approach is that fewer components are needed to build the application. Most algorithms also keep working properly without special casing. Therefore this is usually easier then lets say a null value for the end-date.

During form

The first step that can be taken is to consider when the current situation was created. In the during form we specify the interval (usually as closed interval) during which a certain state was valid. This can be in the past but also in the future as some kind of prediction or planning. Frank lived in Laren during the interval [1-may-1998:7-aug-2006]. And then moved to Baarn.

Closed or Semi-Open

Chris Date works in his book with closed intervals. It is significantly easier to develop the theory with closed intervals, and i have always worked with closed intervals. Yet the Joda-time library works with semi-open intervals. This has some advantages.

  • it is practical for transaction time purposes, as the same timestamp is used to end one interval and start a new one.
  • it makes conversions practical between granularities. e.g. a date interval is at the same time a millisecond interval.

    So I wil sometimes still give examples with closed intervals, but the code wil be based on the joda-time concept interval which is right open. We shall perhaps need an new implementation.

Interval operators and relations

Intervals based on discrete time units can have 13 relative positions. Thus an interval type needs 7 operators to determine these positions. We develop these for semi-open intervals.