Ion Fusion Documentation
Release 0.38a1-SNAPSHOT (2026-04-16T19:45:37.790Z)

Module /fusion/timestamp

Immutable point-in-time values with local offset.

The semantics of Fusion timestamp values are identical to Ion timestamps.

< procedure
(< a b)

Returns true if a is less than b. Numbers are compared without regard to precision or negative zeros; if the values have different concrete types they are both coerced to decimal. Timestamps are compared to each other without regard to precision or local offset. Annotations are ignored.

Warning: The behavior of this procedure is undefined for values +inf, -inf, and nan. See issue #64.

<= procedure
(<= a b)

Returns true if a is less than or equal to b. Numbers are compared without regard to precision or negative zeros; if the values have different concrete types they are both coerced to decimal. Timestamps are compared to each other without regard to precision or local offset. Annotations are ignored.

Warning: The behavior of this procedure is undefined for values +inf, -inf, and nan. See issue #64.

= procedure
(= left right)

Returns true if the arguments are equivalent in shape and content, possibly by coercing values to a common type. Annotations and precision are ignored.

  • Any value is = to itself.
  • Nulls of any type are = to each other.
  • Bools are = in the obvious way.
  • Numbers are = when they represent the same numeric value, without regard to precision or negative zeros. When a float is compared to an int or decimal, it is coerced to a decimal.
  • Timestamps are = when they represent the same point-in-time, without regard to precision or local offset.
  • Strings and symbols are = (interchangably) when they contain the same sequence of code points.
  • Blobs and clobs are = (interchangably) when they contain the same sequence of bytes.
  • Pairs are = when their heads and tails are =.
  • Sequences are = when they have the same size, and elements at the same index are =.
  • Structs are = when they have the same set of field names, and each name maps to a set of elements that are =.
  • Void is = only to itself.
  • Exceptions are not thrown due to mismatched types; instead the result is false.

For example:

(= null (quote a::null))             --> true
(= null null.clob)                   --> true
(= 1 1.00)                           --> true
(= 0 -0e-3)                          --> true
(= 2014T 2014-01-01T02:00+02:00)     --> true
(= 2014T 2014)                       --> false

(= "text" (quote text))              --> true
(= "text" (quote a::"text"))         --> true

(= [1, 2] (sexp 1 2.00))             --> true
(= null.list [])                     --> false

(= (struct "f" 1) (mutable_struct "f" 1.0))   --> true
(= {f:1, f:1} {f:1})                          --> false

At present, the coercion of float to decimal is precise, without rounding to approximate a prettier decimal form. This may lead to strange behavior since most decimal numbers don't have a precise binary representation:

(= 1.2 1.2e0)  --> false
(= 1.5 1.5e0)  --> true

It's possible this may change in a future release.

Warning: The behavior of this procedure is undefined for values +inf, -inf, and nan. See issue #64.

> procedure
(> a b)

Returns true if a is greater than b. Numbers are compared without regard to precision or negative zeros; if the values have different concrete types they are both coerced to decimal. Timestamps are compared to each other without regard to precision or local offset. Annotations are ignored.

Warning: The behavior of this procedure is undefined for values +inf, -inf, and nan. See issue #64.

>= procedure
(>= a b)

Returns true if a is greater than or equal to b. Numbers are compared without regard to precision or negative zeros; if the values have different concrete types they are both coerced to decimal. Timestamps are compared to each other without regard to precision or local offset. Annotations are ignored.

Warning: The behavior of this procedure is undefined for values +inf, -inf, and nan. See issue #64.

adjust_day procedure
(adjust_day ts period)

Returns a timestamp that's period days after (or before, if negative) ts. The result will have the same precision and local offset.

ts must be a non-null timestamp and period must be a non-null int (limited to the 32-bit range).

adjust_hour procedure
(adjust_hour ts period)

Returns a timestamp that's period hours after (or before, if negative) ts. The result will have the same precision and local offset.

ts must be a non-null timestamp and period must be a non-null int (limited to the 32-bit range).

adjust_minute procedure
(adjust_minute ts period)

Returns a timestamp that's period minutes after (or before, if negative) ts. The result will have the same precision and local offset.

ts must be a non-null timestamp and period must be a non-null int (limited to the 32-bit range).

adjust_month procedure
(adjust_month ts period)

Returns a timestamp that's period months after (or before, if negative) ts. The result will have the same precision and local offset. In general, only the year and month fields will change, but the day may change to account for leap-days.

ts must be a non-null timestamp and period must be a non-null int (limited to the 32-bit range).

adjust_second procedure
(adjust_second ts period)

Returns a timestamp that's period seconds after (or before, if negative) ts. The result will have the same precision and local offset.

ts must be a non-null timestamp and period must be a non-null int (limited to the 32-bit range).

adjust_year procedure
(adjust_year ts period)

Returns a timestamp that's period years after (or before, if negative) ts. The result will have the same precision and local offset. In general, only the year field will change, but the day may change to account for leap-days.

ts must be a non-null timestamp and period must be a non-null int (limited to the 32-bit range).

epoch_millis_to_timestamp procedure
(epoch_millis_to_timestamp epoch_millis)

Returns a timestamp for the point in time given as the number of milliseconds since 1970-01-01T00:00Z. The epoch_millis may be a decimal or int.

is_timestamp procedure
(is_timestamp value)

Determines whether a value is of type timestamp, returning true or false.

string_to_timestamp procedure
(string_to_timestamp string)

Converts a string to a timestamp, recognizing (only) Ion formatted data. Returns null.timestamp when given null.string.

(string_to_timestamp null.string)        ==> null.timestamp
(string_to_timestamp "2013-11-13T")      ==> 2013-11-13
(string_to_timestamp "null.timestamp")   ==> ERROR
timestamp procedure
(timestamp year month? day? hour? minute? second? offset?)

Returns a timestamp representing a specified point in time.

The year is required, and other fields can be added in increasing precision. Acceptable combinations of arguments being present or absent align with the combinations of fields allowed by Ion timestamps. Optional arguments that are not present are equivalent to being void.

  • When present, month must be an actual integer.
  • When present, day must be an actual integer and month must be present.
  • When either is present, hour and minute must both be actual integers, and month and day must be present.
  • When present, second must be an actual integer or decimal, and all preceding arguments must be present.
  • When present, offset must be an actual integer denoting the minutes of local offset; void denotes the unknown local offset -00:00. The offset is ignored when the hour and minutes are not provided.

For example:

(timestamp 2016)                       ==> 2016T
(timestamp 2016 7)                     ==> 2016-07T
(timestamp 2016 7 1)                   ==> 2016-07-01
(timestamp 2016 7 1 9 5)               ==> 2016-07-01T09:05-00:00
(timestamp 2016 7 1 9 5 (void) -420)   ==> 2016-07-01T09:05-07:00
(timestamp 2016 7 1 9 5 6. 0)          ==> 2016-07-01T09:05:06+00:00
(timestamp 2016 7 1 9 5 6. (void))     ==> 2016-07-01T09:05:06-00:00
(timestamp 2016 7 1 9 5 6.123)         ==> 2016-07-01T09:05:06.123-00:00
timestamp_at_day procedure
(timestamp_at_day ts)

Returns a timestamp that represents the same point-in-time as ts, with precision DAY.

timestamp_at_minute procedure
(timestamp_at_minute ts)

Returns a timestamp that represents the same point-in-time as ts, with precision MINUTE. Local offset is preserved.

timestamp_at_month procedure
(timestamp_at_month ts)

Returns a timestamp that represents the same point-in-time as ts, with precision MONTH.

timestamp_at_second procedure
(timestamp_at_second ts)

Returns a timestamp that represents the same point-in-time as ts, with precision SECOND. Local offset is preserved.

timestamp_at_year procedure
(timestamp_at_year ts)

Returns a timestamp that represents the same point-in-time as ts, with precision YEAR.

timestamp_day procedure
(timestamp_day ts)

Returns the day of ts in its local time if its precision is DAY or finer, returns void otherwise.

timestamp_hour procedure
(timestamp_hour ts)

Returns the hour in the day of ts in its local time if its precision is MINUTE or finer, returns void otherwise.

timestamp_minute procedure
(timestamp_minute ts)

Returns the number of minutes past the hour of ts in its local time if its precision is MINUTE or finer, returns void otherwise.

timestamp_month procedure
(timestamp_month ts)

Returns the month of ts in its local time if its precision is MONTH or finer, returns void otherwise.

timestamp_now procedure
(timestamp_now)

Returns a timestamp representing "now". At present the local offset is unspecified, but that may change in the future.

timestamp_offset procedure
(timestamp_offset ts)

Returns the local offset of ts as an integer in minutes if its offset is known, returns void otherwise.

timestamp_put_offset procedure
(timestamp_put_offset ts offset)

Returns a timestamp that has the same time fields (year, month, ...) as ts, with local offset equal to offset minutes. The result may represent a point-in-time different from ts. offset must have magnitude less than 1440 (24 hours).

timestamp_second procedure
(timestamp_second ts)

Returns the number of seconds past the minute in ts in its local time if its precision is SECOND, returns void otherwise.

timestamp_to_epoch_millis procedure
(timestamp_to_epoch_millis timestamp)

Given a non-null timestamp, returns the same point in time represented as the number of milliseconds since 1970-01-01T00:00Z. The result is a decimal.

timestamp_to_string procedure
(timestamp_to_string timestamp)

Converts a timestamp to a string in Ion format. Returns null.string when given null.timestamp.

(timestamp_to_string null.timestamp)   ==> null.string
(timestamp_to_string 2013-11-13T)      ==> "2013-11-13"
timestamp_with_offset procedure
(timestamp_with_offset ts offset)

Returns a timestamp at the same point-in-time as ts, but with local offset equal to offset minutes. The returned timestamp may have different time fields to maintain the same point-in-time. Expects ts to have precision MINUTE or finer.

timestamp_year procedure
(timestamp_year ts)

Returns the year of ts in its local time.