Skip to content

Time

Source: std/time.mw.

Clocks, sleeping and calendar conversion (proleptic Gregorian, UTC).

struct DateTime {
year: i64;
month: i64; // 1..12
day: i64; // 1..31
hour: i64;
minute: i64;
second: i64;
weekday: i64; // 0 = Sunday
yday: i64; // 0-based day of the year
}
fn time_now_ns() -> i64

Nanoseconds since 1970-01-01 00:00:00 UTC (negative on error).

fn time_mono_ns() -> i64

Nanoseconds from an arbitrary starting point; never goes backwards.

fn time_unix() -> i64
fn sleep_ns(ns: i64)
fn sleep_ms(ms: i64)
fn is_leap_year(y: i64) -> bool
fn days_in_month(y: i64, m: i64) -> i64
fn days_from_civil(y: i64, m: i64, d: i64) -> i64

Days since 1970-01-01 for a civil date (Howard Hinnant’s algorithm).

fn datetime_from_unix(t: i64) -> DateTime

Seconds since the epoch -> broken-down UTC time.

fn datetime_to_unix(dt: DateTime) -> i64
fn time_pad2(buf: *u8, n: i64)
fn datetime_format_iso(buf: *u8, dt: DateTime) -> i64

“YYYY-MM-DDTHH:MM:SSZ” (20 bytes, no terminator) -> returns 20.