Lyricdev
GitHub

std.time

Measures time, and reads and writes dates, times of day and time zones.

The main types are Duration, a span; Instant, a moment on the wall clock in UTC; Monotonic, a moment on the clock that only moves forward, for how long something takes; Date, Time and DateTime, the proleptic Gregorian calendar with RFC 3339 text; and Zone, UTC, a fixed offset or a zone of the time zone database (TZif, RFC 8536). DateTime.format and DateTime.parseWith use the date patterns of UTS #35. sleep and the timers live in std.task.

Examples

import std.io { println };
import std.core { ParseError };
import std.time { Date, Duration, TimeError };

fn main(): void throws [TimeError, ParseError] {
    let d = try Date.of(2026, 10, 24);
    println(d.plusDays(10));
    println(try Duration.parse("1h30m"));
    println(try Date.parse("2024-02-29"));
}
2026-11-03
1h30m0s
2024-02-29

Types

Duration struct — A span of time in whole nanoseconds, negative or not: some 292 years either way.
Instant struct — A moment on the wall clock, in nanoseconds since 1970-01-01T00:00:00Z — POSIX time, no leap seconds counted: the years 1677 to 2262.
Monotonic struct — A moment on the clock that only moves forward: for how long something takes, never for the time of day.
TimeErrorKind enum — The reason for a TimeError: a value that does not exist; no zone database on the system; a zone the database does not have.
TimeError struct — The error for what is no date, no time of day, no offset — February 30th, 24:00, an offset of 90 seconds — or a zone that cannot be loaded, its kind saying why.
Weekday enum — The days of the week, Monday first (ISO 8601).
Date struct — A day of the proleptic Gregorian calendar.
Time struct — A time of day: hours 0–23, minutes and seconds 0–59 — no leap second, which POSIX time does not count —, nanoseconds.
Zone struct — A time zone: UTC, a fixed offset, or a zone of the database — its transitions and the rule for the years beyond them (TZif, RFC 8536; a POSIX TZ string).
ZoneInfo struct — What a zone says about a moment.
DateTime struct — A date and a time of day at an offset from UTC: the moment it names, and how it was written.