Skip to content
Systems programming for what’s next.
— Vex

time ​

std/time separates three concepts that must not be mixed:

TypeMeaningUse
TimeUTC Unix timestampstorage, protocols, calendar and display
Instantprocess-local monotonic readingelapsed time, deadlines, timers
Durationsigned nanosecond intervalarithmetic and delays

Monotonic timing ​

vex
import { Duration, Instant, sleep } from "time";

let started = Instant.now();
sleep(Duration.milliseconds(2));
let elapsed = started.elapsed();

Do not persist or transmit Instant.asNanos(): its epoch is process-local. Raw monotonicNow() and sleepDuration() compatibility APIs no longer exist.

Wall time and checked arithmetic ​

vex
import { Duration, Time } from "time";

let now = Time.now();
match now.checkedAdd(Duration.seconds(30)) {
    Some(deadline) => $println(deadline.toString()),
    None => $panic("timestamp overflow"),
}

Default arithmetic panics on overflow. Use checked* for recoverable failure or saturating* when clamping is the intended policy.

Parsing ​

vex
import { parse_duration, parse_rfc3339 } from "time";

let timestamp = parse_rfc3339("2024-03-15T14:30:45.123456789+03:00");
let timeout = parse_duration("2d3h4m5.006007008s");

RFC 3339 parsing validates civil dates, leap years, clock fields, numeric offsets, trailing input and the exact signed-nanosecond range. Calendar conversion is constant-time. Duration parsing supports d, h, m, s, ms, us, µs and ns with signs and fractional components.

The fixed-width RFC 3339 calendar/time core uses direct inline decimal scans; the variable fraction and UTC-offset tails retain their strict validating path. Parsing stays allocation-free and does not use a native date parser.

Timers ​

Timer and Ticker use the monotonic clock. Tickers advance from their prior phase and skip missed periods, avoiding cumulative drift. after(Duration) delivers one wall-clock Time through a Channel<Time>.

Platform behavior ​

The package resolves native.macos.vxc, native.linux.vxc or native.windows.vxc; it has no generic native fallback. POSIX sleep resumes after signal interruption. Windows prefers a high-resolution waitable timer.

IANA zone lookup is currently a manifest-owned native feature. A pure-Vex TZif parser is the remaining portability milestone.

Module map ​

FilePurpose
time_type.vxTime, calendar accessors and checked arithmetic
instant.vxmonotonic Instant and deadline arithmetic
duration.vxDuration policies and formatting
parse.vxRFC 3339 and Duration parsing
conversions.vxO(1) Gregorian conversion
helpers.vxtimers, tickers and package helpers
location.vxUTC, local, fixed and IANA locations
native.*.vxctarget-specific clock and sleep boundaries

See the generated API reference for the complete surface.

Released under the MIT License.