langur

durations

Durations use the dr// token. They loosely follow ISO 8601 syntax (see the Wikipedia article section on durations). The "P" is optional and spaces are allowed between each number. Time durations must include a capital T first. The following shows the general syntax, with [n] as a placeholder for an integer. All parts are optional, but there must be at least one. They also must be in order (most significant portions first).

dr/P[n]Y[n]M[n]DT[n]H[n]M[n[.n]]S/ dr/P[n]W/

The letters represent Years, Months, Days, then Hours, Minutes, and Seconds (including fractions of seconds), or Weeks. Lowercase letters may be used for improved readability (except for the T)

Fractional seconds may be 1 to 9 digits.

Durations are not converted to nanoseconds, but kept as 7 separate numbers. Here are some examples of duration literals. Note the adding or subtraction of durations on date-times to yield a new date-time.

type conversion and type checking

Using type names helps to do conversion and type checking. See the built-ins, operators, and type pages for details.

The duration type name can be used to generate a duration value duration value from a number (nanoseconds) or a hash.

Conversion to a hash (using hash(d/12y 3m/)) will give you all the data about a duration value in separate hash fields.

Using the number type for conversion (number(dr/12y 3m/)), it will convert it to nanoseconds. A "month" and a "year" are hard to define in this way. Currently, a "year" is the equivalent of 365.25 days and a "month" of 30.4375 days (365.25 / 12). This is a reason to use durations instead of simple numbers.

Using the string type (string(dr/12y 3m/)) will produce an ISO 8601 duration string.