std/time
On this page
Index
- const
RFC3339 - const
RFC1123 - const
DATE - const
TIME - const
RFC3339_LAYOUT - const
RFC1123_LAYOUT - const
DATE_LAYOUT - const
TIME_LAYOUT - type
Zone- method
Zone.display - method
Zone.name - method
Zone.offset_at - method
Zone.abbreviation_at
- method
- type
ZoneErr- method
ZoneErr.display
- method
- type
Date- method
Date.weekday - method
Date.add_days - method
Date.add_months - method
Date.days_until - method
Date.display
- method
- type
ClockTime - type
Civil - type
Weekday- method
Weekday.number
- method
- type
Ambiguity - type
CivilErr- method
CivilErr.display
- method
- type
Ticker- method
Ticker.wait - method
Ticker.reset
- method
- type
Layout- method
Layout.display - method
Layout.format - method
Layout.parse
- method
- type
ParseErr- method
ParseErr.display
- method
- type
LayoutErr- method
LayoutErr.display
- method
- fn
utc - fn
zone - fn
fixed - fn
local - fn
civil - fn
instant - fn
date - fn
weekday_from - fn
truncate - fn
round - fn
ticker - fn
layout - fn
format - fn
parse - fn
check_layout
Constants
RFC3339
const RFC3339: Str = "{year}-{month}-{day}T{hour}:{minute}:{second}{frac}{offset}"RFC1123
const RFC1123: Str = "{weekday:short}, {day} {month:short} {year} {hour}:{minute}:{second} {zone}"HTTP dates.
DATE
const DATE: Str = "{year}-{month}-{day}"TIME
const TIME: Str = "{hour}:{minute}:{second}"RFC3339_LAYOUT
const RFC3339_LAYOUT: Layout = layout(RFC3339)RFC1123_LAYOUT
const RFC1123_LAYOUT: Layout = layout(RFC1123)DATE_LAYOUT
const DATE_LAYOUT: Layout = layout(DATE)TIME_LAYOUT
const TIME_LAYOUT: Layout = layout(TIME)Types
Zone
struct Zone {}A time zone: a handle to its rules. Equal when the names (and, for
fixed, the offsets) are equal; displays as its name.
Zone.display
fn (z: Zone) display() -> StrZone.name
fn (z: Zone) name() -> StrZone.offset_at
fn (z: Zone) offset_at(t: Time) -> DurationThe offset from UTC at that instant.
Zone.abbreviation_at
fn (z: Zone) abbreviation_at(t: Time) -> Str“CET”, “CEST”.
ZoneErr
enum ZoneErr {
Unknown(name: Str)
NoLocal(msg: Str)
}Displays as unknown time zone "Mars/Olympus" or
cannot determine the local time zone: the system zone is not set.
ZoneErr.display
fn (e: ZoneErr) display() -> StrDate
struct Date {
year: Int
month: Int
day: Int
} derive Ord, JsonA calendar date in the proleptic Gregorian calendar.
Date.weekday
fn (d: Date) weekday() -> WeekdayDate.add_days
fn (d: Date) add_days(n: Int) -> DateDate.add_months
fn (d: Date) add_months(n: Int) -> DateClamps the day: Jan 31 + 1 month is Feb 28 or 29.
Date.days_until
fn (d: Date) days_until(o: Date) -> IntDate.display
fn (d: Date) display() -> Str“2026-10-09”.
ClockTime
struct ClockTime {
hour: Int
minute: Int
second: Int
nanos: Int
} derive Ord, JsonA wall clock time of day.
Civil
struct Civil {
date: Date
time: ClockTime
offset: Duration
zone: Str
} derive JsonA wall clock reading in a zone: what civil(t, z) returns.
Weekday
enum Weekday {
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
} derive Display, Ord, JsonWeekday.number
fn (w: Weekday) number() -> IntThe ISO 8601 number of the day: Monday 1 to Sunday 7 (decision 0414).
Ambiguity
enum Ambiguity {
Earlier
Later
Reject
}What instant does with a civil time that falls in a daylight saving
gap (does not exist) or overlap (exists twice). Earlier gives the
earlier instant and Later the later one, so Earlier is never after
Later: for a gap, 02:30 on 2026-03-08 in New York is 01:30 EST
(Earlier, the clock moved back by the gap) or 03:30 EDT (Later);
for an overlap, 01:30 on 2026-11-01 is 01:30 EDT or 01:30 EST.
CivilErr
enum CivilErr {
Invalid(msg: Str)
Skipped(at: Str)
Repeated(at: Str)
}Displays as invalid civil time: month 13 out of range 1 to 12,
2026-03-08T02:30:00 America/New_York does not exist (skipped by a daylight saving change), or 2026-11-01T01:30:00 America/New_York happens twice (repeated by a daylight saving change).
CivilErr.display
fn (e: CivilErr) display() -> StrTicker
struct Ticker {
clock: Clock
period: Duration
next_ns: Atomic[Int]
}A clock’s ticks every period (Go’s time.Ticker without a goroutine):
wait sleeps until the next tick and returns its time; ticks that a
slow caller missed are dropped, as Go’s channel of one drops them, and
the phase is kept (decision 0414). Copies share the schedule.
Ticker.wait
fn (t: Ticker) wait() -> Time uses clockTicker.reset
fn (t: Ticker) reset(period: Duration) -> Ticker uses clockRestarts the schedule: the next tick one (new) period from now.
Layout
struct Layout {}A layout parsed once. Hot code should use it: format and parse with a string
layout parse the text on every call (5.4x and 4.7x of Go’s wall), while a const Layout
runs at 2.03x and 1.90x (bench/results/std-twin-rows2-2026-11-03.md).
A layout parsed once: const ISO: Layout = layout("{year}-{month}-{day}")
parses it on first use (decision 0332), and format and parse then
skip the layout walk. Displays as the layout text; equal when the texts
are.
Layout.display
fn (l: Layout) display() -> StrLayout.format
fn (l: Layout) format(t: Time, z: Zone) -> StrSame text as time.format(t, z, text).
Layout.parse
fn (l: Layout) parse(s: Str, z: Zone) -> Time ! ParseErrSame result as time.parse(s, text, z).
ParseErr
struct ParseErr {
input: Str
layout: Str
at: Int
msg: Str
}Displays as at byte 5 of "2026-1x-09": expected 2 digit month.
ParseErr.display
fn (e: ParseErr) display() -> StrLayoutErr
struct LayoutErr {
layout: Str
msg: Str
}Displays as bad layout "{yr}": unknown field {yr}.
LayoutErr.display
fn (e: LayoutErr) display() -> StrFunctions
utc
fn utc() -> Zoneutc() needs no zone data.
zone
fn zone(name: Str) -> Zone ! ZoneErrAn IANA name: “Europe/Berlin”. Pure: the data is embedded in the program.
fixed
fn fixed(name: Str, offset: Duration) -> ZoneA zone with one offset forever (“UTC+2” style names); faults past 24h.
local
fn local(env: Env) -> Zone ! ZoneErr uses envThe machine’s zone: TZ, then the system setting. A fake Env without
TZ gives utc().
civil
fn civil(t: Time, z: Zone) -> Civilinstant
fn instant(date: Date, time: ClockTime, z: Zone, ambiguity: Ambiguity = Ambiguity.Reject) -> Time ! CivilErrdate
fn date(year: Int, month: Int, day: Int) -> Date ! CivilErrweekday_from
fn weekday_from(n: Int) -> Weekday?The weekday of an ISO 8601 number (1 Monday to 7 Sunday), None outside 1 to 7.
truncate
fn truncate(t: Time, d: Duration) -> Timet rounded down to a multiple of d since the zero time (January 1 of year 1, UTC), Go’s Time.Truncate: for a d that divides a day this is the start of the UTC minute, hour or day. d <= 0 returns t.
round
fn round(t: Time, d: Duration) -> Timet rounded to the nearest multiple of d (halves up), Go’s Time.Round.
ticker
fn ticker(clock: Clock, period: Duration) -> Ticker uses clockA ticker whose first tick is one period from now; faults for a period of 0 or less (Go’s NewTicker panics).
layout
fn layout(text: Str) -> LayoutFaults on a bad layout (a constant layout is checked at compile time).
format
fn format(t: Time, z: Zone, layout: Str) -> StrFaults on a bad layout (a constant layout is checked at compile time).
{frac} and {frac:N} include their leading .: write {second}{frac:7}, not {second}.{frac:7}.
parse
fn parse(s: Str, layout: Str, z: Zone) -> Time ! ParseErrStrict: accepts exactly the layout. z applies when the text has no
offset.
check_layout
fn check_layout(layout: Str) -> () ! LayoutErr