langur

date and time

A datetime literal uses a subset of ISO 8601 syntax, extended format only.

An empty datetime literal generates the current datetime in your time zone. A datetime literal with only a time zone offset or Z (UTC) specified generates the current datetime in that time zone.

The "frac" modifier determines if nanoseconds (fractional seconds) are included in a "now" datetime (defaults to false).

If not specifying a time zone only, the year, month, and day are required. Hours, minutes, and seconds are optional (defaulting to 0).

The date and time are separated by either a space or a capital T.

Dates are Gregorian or proleptic Gregorian.

Second fractions (after a decimal point) may be 1 to 9 digits.

The operators ==, >, <=, etc. can be used to compare datetimes.

time zone

The default time zone used is your local time zone.

The letter Z gives the UTC time zone (same as +00:00).

formatting

A formatting string may be passed to the string type or the datetime type—such as string(dt//, fmt=formatstring) or datetime(string, fmt=formatstring)—or used in a datetime interpolation modifier.

The Go time package expects the following numbers and formats in a format string.

A number preceeded with a zero is zero-padded and with an underscore is space-padded.

datetime math

Durations can be added to or subtracted from datetimes. You can also add or subtract a number (nanoseconds), but a duration might give a more predicatable result in terms of "years" and "months."

dt/2015-05-01/ + dr/1Y 1M 1D T 1H/ dt/2015-05-01/ - dr/1Y 1M 1D T 1H/ # adding or subtracting durations

dt/2015-05-01/ + 1000 dt/2015-05-01/ - 1000 # adding or subtracting nanoseconds

You can get the difference between 2 datetime values, yielding a duration (in years, months, etc.).

dt/2015-05-01/ - dt/2016-06-02T01:01:01.000000001/ == dr/1Y 1M 1D T 1H 1M 1.000000001S/

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 datetime type name can be used to generate a datetime value or to convert a datetime value to another time zone, such as datetime(123).

Conversion to a hash (using hash(dt//)) will give you all the data about a datetime value in separate hash fields.

When converting a datetime to a number (number(dt//)), it will return the number of nanoseconds since the start of January 1, 1970 UTC.

Conversion to a string, without a second argument (string(dt//)), will produce an ISO 8601/RFC 3339 timestamp. A second argument would be a format string to use. This formatting is currently the same as that used by the Go time package.