std.time - ZZ
Clocks, sleeps, and calendar dates. Dates are {str: int} dicts (year, month, day, hour, min, sec). Parse/format are UTC RFC3339 (...Z) only; invalid input falls back to epoch so callers stay total.
import std.timePurpose
Section titled “Purpose”std.time provides wall-clock and monotonic time, sleeps (cooperative — yield green threads), and calendar-date math on dict-based dates. All parse/format ops are UTC RFC3339; invalid input falls back to epoch (total).
Quickstart
Section titled “Quickstart”import std.time
start := time.now_ms()time.sleep_ms(1000)elapsed := time.now_ms() - startprintln("slept {elapsed}ms")
d := time.parse_rfc3339("2024-02-29T12:30:45Z")println(time.format_rfc3339(d)) // 2024-02-29T12:30:45Zprintln(time.add_days(d, 1)["day"])println(time.diff_days(d, time.make_date(2024, 2, 28, 0, 0, 0))) // 1Durations (pure-ZZ)
Section titled “Durations (pure-ZZ)”Spans as integer microseconds:
time.micros(1_000_000) // 1 second in microstime.millis(1000) // 1000 ms in microstime.secs(1) // 1 sec in microsd := time.millis(1000) // duration spantime.to_micros(d) // convert duration span to microstime.to_millis(d)time.to_secs(d)time.to_nanos(d)time.sleep(d) // sleep a duration spanProduction patterns
Section titled “Production patterns”import std.time
// Measure elapsed cooperativelystart := time.monotonic_nanos()// ... work ...elapsed_ms := (time.monotonic_nanos() - start) / 1_000_000
// Validate before usingd := time.parse_rfc3339("2024-02-29T12:30:45Z")if time.date_valid(d["year"], d["month"], d["day"]) { // safe to use d}API reference
Section titled “API reference”28 entries. Signatures come from the compiler’s own FuncSig table, so they match the runtime exactly; descriptions come from the module guide.
See also
Section titled “See also”std.math— Rounding, roots, powers, trigonometry, predicates and numeric aggregates.
Full index: API reference · Standard library