^ (Absolute)

The absolute type in Rax represents an duration of an absolute amount of time. For example, "one day" or "thirty-three seconds." Unlike with relative duration which will be described in the next section, the actual length of the absolute does not depend on the starting point of the duration. One day is always one day, regardless of whether we're counting from the 1st of September or from the 1st of October. Things are different with relative durations, like 1 month. The absolute type is denoted by the ^ symbol in Rax. As with all temporal types in Rax, a string in ISO 8601 format can be cast to a valid typed value. Also, numbers and reals can be cast to an absolute value.

    ^: one'day := (^)"P1D";
    ^: epsilon := (^)"PT00:00:00.0001";
    ^: halfday := (^).5;
         

Like a number, an absolute can be negative, for example minus one week. Also like with numbers the unary +, -, and # work as expected. For example:

    ^: a := (^)"P-7D";
    `print a;     // Output: P-1W
    `print -a;    // Output: P1W
    `print #a;    // Output: P1W
    `print +-#-a; // Output: P-1W
         

Multiplying two duration in Rax is considered an error, for what would the result be? However, adding an absolute duration to a point in time results in a new point in time and hence is allowed in Rax. The same holds for adding two absolutes and multiplying a number and an absolute. Continuing the previous example, these are all valid expressions except the first:

    `print (@)"now" * (@)"now";  // !!! This will cause an error.
    `print one'day + halfday;
    `print (@)"now" + halfday;
    `print (@)"now" - halfday;
    `print one'day == 2 * halfday;
         

The absolute difference between (though not the sum of) two points in time is a valid operator and can be calculated using the ^ operator, for example, like so:

    @: birthday := (@)"2014-08-20T12:33:15";
    ^: baby_age := (@)"now" ^ birthday;
         

Note that the time difference operator is the ^ and not the minus sign. This is because there is also another type of duration: the relative duration. The table below summarizes all operators defined on ^.

Table 4.2. Operators defined on ^

SyntaxExplanation
ad1 := ad2Assignment
ad1 == ad2Equals
ad1 != ad2Not equals
ad1 < ad2Less than
ad1 > ad2Greater than
ad1 <= ad2Less than or equal to
ad1 >= ad2Greater than or equal to
ad1 + ad2Addition
ad1 - ad2Subtraction
+adUnary plus
-adUnary minus
#adMagnitude value
ad1 % ad2Modulo. It works exactly as you would expect it to, for example: (^)"P1W" % (^)"P2D" == (^)"P1D".
ad * nMultiplication, where n is of type #. For example: (^)"P1W" * 2 == (^)"P2W".
n * adMultiplication, where n is of type #. For example: 2 * (^)"P1W" == (^)"P2W".
ad / nDivision, where n is of type #. For example: (^)"P1W" / 2 == (^)"P3DT12H".
ad * rMultiplication, where r is of type &. For example: (^)"P1W" * 2.5 == (^)"P2W3DT12H".
r * adMultiplication, where r is of type &. For example: 2.5 * (^)"P1W" == (^)"P2W3DT12H".
ad / rDivision, where r is of type &. For example: (^)"P1W" / 3.5 == (^)"P2D".
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 - 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".