Time.DateTime

lib/Time/DateTime.gob

An instant in a time zone: when something happens at a place. It has both a position on the timeline and a reading of the calendar and the clock, and moves both ways -- by elapsed time with after, and by the calendar with shift, which keeps the wall-clock time across a change to daylight saving time.

The offset is worked out when a value is made, so reading the calendar or the clock is integer arithmetic with no look-up in the zone's rules.

A wall-clock reading does not always name exactly one instant: when the clocks go forward an hour of readings is skipped, and when they go back an hour is repeated. resolve says which happened; everything that turns a reading into a DateTime by itself -- of, shift -- settles it the way RFC 5545 does: by the offset in force before the transition. A skipped reading lands as far after the transition as it was meant to be after the last reading before it, and a repeated one is its first occurrence.

type DateTime
type Resolution = Unique(DateTime) | Skipped { forward : DateTime, backward : DateTime, at : DateTime } | Repeated { earlier : DateTime, later : DateTime }

What a wall-clock reading names in a zone: one instant; none, because the clocks skipped over it -- forward reads it with the offset before the transition, backward with the one after, and at is the transition itself, the first instant after the gap; or two, because the clocks went back over it.

fun fromInstant : fun(Instant, Zone) -> DateTime
fun now : fun(Zone) -> DateTime

The time now in z. There is no form without a zone: which zone a program runs in is the system's setting, and Zone.system() says so where it is used.

fun instant : fun(DateTime) -> Instant
fun zone : fun(DateTime) -> Zone
fun offset : fun(DateTime) -> Offset
fun plain : fun(DateTime) -> PlainDateTime

The calendar and clock reading.

fun inZone : fun(DateTime, Zone) -> DateTime

The same instant in another zone.

fun after : fun(DateTime, Duration) -> DateTime
fun resolve : fun(PlainDateTime, Zone) -> Resolution

What the reading p names in z.

fun of : fun(PlainDateTime, Zone) -> DateTime

The reading p in z, settled by the offset before a transition if the clocks skipped or repeated it: 02:30 on the night the clocks go forward from 02:00 to 03:00 is 03:30, and 01:30 on the night they go back is the first 01:30. resolve says which happened, for a caller that must decide itself.

fun shift : fun(DateTime, Period) -> DateTime

Shifts the calendar reading and keeps the clock reading, resolving the result as of does, except that a repeated reading keeps the offset dt had if it can: shifting the second 01:30 of a night by nothing gives the second 01:30, not the first.

fun startOfDay : fun(DateTime) -> DateTime

The first instant of dt's day in its zone. Not always midnight: where the clocks went forward at midnight, the day starts at the first instant after the gap, never extrapolated across it; where midnight was repeated, at the first one.

fun parse : fun(String) -> Option DateTime

RFC 9557, as show writes it. The bracketed zone is required: a zone name, or an offset for a fixed zone. The offset must be the one the zone has at that reading -- if the zone's rules have changed since the text was written, the text no longer says one instant, and this is None -- unless it is Z, which says only the instant. A zone the system has no file for is None.

instance Eq DateTime
instance Ord DateTime

By instant, then by zone id, so that the order agrees with == and sorts chronologically.

instance Hash DateTime
instance Show DateTime

RFC 9557: the reading, its offset, and the zone in brackets, 2026-10-18T14:03:07.52-04:00[America/Toronto].