module std.time
std.time — time, calendar and clocks (§17). Decisions D-3100..D-3119.
The builtin types live in std.core (the prelude): Duration (i64 ns), Time (UTC instant, i64 ns since the epoch),
Instant (monotonic), Date (days since the epoch), LocalDateTime (wall clock without a zone, i64 ns), Tz
(zone name) and Cron. This module adds the methods, TimeOfDay, ZonedTime, Period, schedules and timers.
The public aliases make the types importable as use std.time { Duration } (D-810). Inside this module the private
aliases Dur, Inst, Tm, Ldt are used so that the public aliases stay "unused" until a program uses them.
Calendar arithmetic, formatting, parsing, cron and the zone database are in the runtime (runtime/src/timelib), the
zones come from the system tz database (D-3104). Patterns: yyyy yy MMMM MMM MM M dd d EEEE EEE HH H hh h a mm m ss s S..
XXX XX X z VV, text in single quotes (D-3103).
Example:
use std.time { Time }
fn main() io {
let start = 2026-11-03T18:00
let meeting = (start + 90m).in(tz"Europe/Berlin")!
print("{meeting.toIso()} {(2026-01-31 + 1.month()).toIso()}")
}2026-11-03T19:30:00+01:00[Europe/Berlin] 2026-02-28
Типы
enum Ambiguity | Which of two equal wall-clock times to take when clocks are set back (§17.2) |
data AmbiguousTime | A local wall-clock time that occurs twice (clocks set back) and Ambiguity.Reject was requested (§17.2). |
type Cron | A cron expression (the type is declared in the prelude; literal cron"0 9 MON-FRI"). |
type Date | A calendar date (the type is declared in the prelude; literal 2026-11-03). |
type Dur | псевдоним · std.time |
type Duration | An exact time interval in nanoseconds (the type is declared in the prelude; use std.time { Duration } imports it with its methods). |
type i64 | псевдоним · std.time |
type Inst | псевдоним · std.time |
type Instant | A reading of the monotonic clock, for measuring intervals (the type is declared in the prelude). |
type Ldt | псевдоним · std.time |
type LocalDateTime | A date and time without a time zone (the type is declared in the prelude; literal 2026-11-03T18:00). |
enum Missed | What every does with ticks missed because the body was slow (§17.4). |
data Period | Calendar interval (§17.1) |
data Schedule | A cron expression bound to a zone (cron"0 9 MON-FRI".in(tz"Europe/Moscow")). |
type Time | A UTC instant, nanoseconds since the Unix epoch (the type is declared in the prelude). |
enum TimeFormat | Predefined text formats of parse (§17.5); every parse also accepts a pattern string instead. |
data TimeOfDay | Wall-clock time of day, 00:00:00 .. |
type Tm | псевдоним · std.time |
type Tz | An IANA time zone (the type is declared in the prelude; literal tz"Europe/Moscow"). |
enum Weekday | Day of the week; Mon is the first. |
data ZonedTime | An instant with a time zone (§17.1). |
Функции
after | Runs body once after d (§17.4). |
at | Runs body at every fire time of schedule until the task is cancelled (§17.4). |
every | Runs body every d until the task is cancelled (§17.4). |
now | Current UTC time (§17.3); same as the prelude now. |
sleep | Suspends the current task (§17.4); same as the prelude sleep. |
today | Today's date in tz (default |