Time

Time :: # (opaque)

A UTC instant with millisecond precision, from 0001-01-01 00:00 to 9999-12-31 23:59:59.999. Use Coordinate.from_time to place it on a date axis, or TimeBounds in Axis.RangeSpec to bound such an axis.

is_eq : _

Compare instants; equal times denote the same millisecond.

from_epoch_millis : I64 -> Try(Time, [TimeOutOfRange(I64)])

Construct an instant from milliseconds since 1970-01-01 00:00 UTC, the unit of JavaScript's Date.now(). Negative values denote earlier instants. Returns TimeOutOfRange(millis) outside the supported years.

expect {
    time = Time.from_epoch_millis(1_762_819_200_000)?
    time.to_str() == "2025-11-11"
}
from_epoch_seconds : I64 -> Try(Time, [TimeOutOfRange(I64)])

Construct an instant from whole seconds since 1970-01-01 00:00 UTC, the unit of Unix timestamps. Returns TimeOutOfRange(seconds) outside the supported years.

from_calendar : Calendar -> Try(Time, [InvalidDate({ year : U16, month : U8, day : U8 }), InvalidTimeOfDay({ hour : U8, minute : U8, second : U8, millisecond : U16 })])

Construct an instant from a UTC calendar date and time of day. Returns InvalidDate({ year, month, day }) for a year outside 1–9999, a month outside 1–12 or a day the month does not have, and InvalidTimeOfDay({ hour, minute, second, millisecond }) for a field beyond its range.

expect {
    time = Time.from_calendar({ year: 2026, month: 11, day: 11, hour: 9, minute: 30 })?
    time.to_str() == "2026-11-11 09:30"
}
to_epoch_millis : Time -> I64

Read the instant as milliseconds since 1970-01-01 00:00 UTC.

to_calendar : Time -> Calendar

Read the UTC calendar date and time of day.

to_str : Time -> Str

Format the instant as a Plotly date string in UTC, such as 2026-11-11, 2026-11-11 09:30, 2026-11-11 09:30:05 or 2026-11-11 09:30:05.250. Trailing zero fields are omitted, so the shortest exact spelling is used. Plotly shows these times unchanged, without converting them to the viewer's time zone.

Calendar

:= {
    year : U16,
    month : U8,
    day : U8,
    hour : U8 ?? 0,
    minute : U8 ?? 0,
    second : U8 ?? 0,
    millisecond : U16 ?? 0,
}

A calendar date and time of day in UTC. month runs from 1 to 12 and day from 1 to the length of that month, including 29 February in leap years. hour (0–23), minute (0–59), second (0–59) and millisecond (0–999) default to zero, so a date alone denotes its midnight. Leap seconds are not represented.