Chapter 4. Temporal types

Table of Contents

@ (Time)
^ (Absolute)
~ (Relative)
| (Interval)
Magic tags for temporal types

Colloquial speech has many temporal conventions that would be very hard to mimic in a programming language. For example, somebody's age can be expressed in years (for an adult) or in weeks (for a baby). To allow unambiguous temporal expressions, Rax provides four different temporal data types: time, absolute (duration), relative (duration) and interval. In Rax, the aforementioned ages would be values of a different type. Temporal types in Rax not only make it easier to read and interpret Rax code, they also allow detection of erroneous or suspicious operations. For example, multiplying two points in time generates a runtime error.

@ (Time)

The time type in Rax represents an exact moment in time, like the 20th of March of the year 2012 at three minutes and sixteen seconds past noon. Actually, the granularity of time in Rax is 1/10.000th of a second. The time type is denoted by the @ symbol in Rax. Temporal data is most often read from a file but it is quite possible to use the ISO 8601 temporal representation[9]. Also the word "now" can be used to get a valid temporal value. For example, like so:

    @: now := (@)"now";
    @: touchdown'UK := (@)"1966-08-20T12:33:15-02";
         

Note the (@) operator that casts a string value to a time value. Some languages have separate date and time types. This is more in line with the context dependent way temporal information is used in colloquial speech where a date can stand for an interval of 24 hours ("I'll fix that tomorrow."), the very start of a day ("On my desk before tomorrow."), and so on. The Rax time type is more like the datetime type found in some SQL dialects. There are, however, no variations like smalldatetime, or parametrized "families" of types like datetime2(<num>), or datetimeoffset(<num>). The table below lists the operators defined on @.

Table 4.1. Operators defined on @

SyntaxExplanation
t1 := t2Assignment
t1 == t2Equals
t1 != t2Not equals
t1 < t2Less than. Returns true, if t1 represents an earlier point in time than t2.
t1 > t2Greater than. Returns true, if t1 represents a later point in time than t2.
t1 <= t2Less than or equal to. Returns true, if t1 represents an earlier or the same point in time as t2.
t1 >= t2Greater than or equal to. Returns true, if t1 represents a later or the same point in time as t2.
t1 ^ t2Absolute difference. Returns an absolute that represents the duration of the interval starting at t1 and ending at t2. For example: (@)"2014-09-11" ^ (@)"2014-09-03" == (^)"P1W1D".
t1 ~ t2Relative difference. Returns a relative that represents the duration of the interval starting at t1 and ending at t2. For example: (@)"2014-09-11" ~ (@)"2014-08-11" == (~)"P1M".
t + adAddition, ad is of type ^. Returns a point in time resulting from shifting t forward by the absolute duration ad. For example: (@)"2014-09-11" + (^)"1W2D" == (@)"2014-09-19".
t + rdAddition, rd is of type ~. Returns a point in time resulting from shifting t forward by the relative duration rd. For example: (@)"2014-09-11" + (~)"1Y1M" == (@)"2015-10-11".
t - adSubtraction, ad is of type ^. Returns a point in time resulting from shifting t backwards by the absolute duration ad. For example: (@)"2014-09-11" - (^)"1W2D" == (@)"2014-09-02".
t - rdSubtraction, rd is of type ~. Returns a point in time resulting from shifting t backwards by the relative duration rd. For example: (@)"2014-09-11" - (~)"1Y1M" == (@)"2013-08-11".
t <: iElement of, i is of type |. Returns true, if the point in time t is an element of the interval i. For example: (@)"2014-09-13" <: (|)"2014-09-11/P1W" is true.
i :> tContains, i is of type |. Returns true, if the interval i contains the point in time t. For example: (|)"2014-09-11/P1W" :> (@)"2014-09-13".




[9] Please note that the ISO 8601 standard does not support Nautical time zone suffixes other that 'Z' (for Zulu or UTC). It does, however, support explicit offsets like "+11:30")