Aye documentation

std.time

std.time: the monotonic clock, the wall clock, sleeping, and UTC dates.

Dates are the proleptic Gregorian calendar in UTC (no time zones, no leap seconds), computed with integer arithmetic only: Howard Hinnant's days-from-civil and civil-from-days. They work before 1970 too. Text forms: RFC 3339 (`2026-10-10T07:20:00Z`) and the IMF-fixdate of an HTTP `Date` header (`Sat, 10 Oct 2026 07:20:00 GMT`).

ParseError

pub error ParseError { Invalid }

monotonicMs

pub fn monotonicMs() u64

Milliseconds on a clock that never goes back (not the time of day; its start is unspecified). Subtract two readings to measure a duration.

now

pub fn now() i64

Milliseconds since 1970-01-01T00:00:00Z (Unix time, leap seconds not counted), from the system's real-time clock. It can jump when the system clock is set; measure durations with `monotonicMs`.

sleep

pub fn sleep(ms: u64)

Waits at least `ms` milliseconds. On wasm32-freestanding it is a busy wait on the host's monotonic clock.

DateTime

pub struct DateTime {
    year: i32
    month: u8
    day: u8
    hour: u8
    minute: u8
    second: u8
    millis: u16
    weekday: u8
    pub fn toUnixMs(self: Self) i64
    pub fn formatRfc3339(self: Self, alloc: Allocator) AllocError![]mut u8
    pub fn formatHttp(self: Self, alloc: Allocator) AllocError![]mut u8
}

A moment in UTC, split into calendar fields. `weekday` is 0 for Sunday to 6 for Saturday.

pub fn toUnixMs(self: Self) i64

Milliseconds since 1970-01-01T00:00:00Z. The fields are not checked and `weekday` is ignored: a `month` of 13 or a `day` of 0 counts on from the neighboring month, as the arithmetic gives it.

pub fn formatRfc3339(self: Self, alloc: Allocator) AllocError![]mut u8

The date as RFC 3339 in UTC, in new memory from `alloc` (free it with `alloc.free`): `2026-10-10T07:20:00Z`, and `2026-10-10T07:20:00.123Z` when `millis` is not 0. RFC 3339 has years 0000 to 9999 only; for others the text is not valid RFC 3339 and `parseRfc3339` rejects it.

pub fn formatHttp(self: Self, alloc: Allocator) AllocError![]mut u8

The date as an HTTP IMF-fixdate (RFC 7231, section 7.1.1.1), in new memory from `alloc` (free it with `alloc.free`): `Sat, 10 Oct 2026 07:20:00 GMT`. The milliseconds are dropped. `weekday` and `month` must be in range (`fromUnixMs` and the parsers give that).

fromUnixMs

pub fn fromUnixMs(ms: i64) DateTime

The calendar fields of `ms` milliseconds since 1970-01-01T00:00:00Z (negative before). Inverse of `DateTime.toUnixMs`.

parseRfc3339

pub fn parseRfc3339(s: []u8) ParseError!DateTime

Parses RFC 3339 `YYYY-MM-DDThh:mm:ss[.f...](Z|+hh:mm|-hh:mm)` and gives the moment in UTC (an offset is subtracted). `T` and `Z` may be lower case. Fractional digits beyond the third are dropped. The date must exist (no February 30) and a second of 60 (a leap second) is rejected, as is any other text: `Invalid`.

parseHttp

pub fn parseHttp(s: []u8) ParseError!DateTime

Parses an HTTP date (RFC 7231, section 7.1.1.1): the IMF-fixdate `Sat, 10 Oct 2026 07:20:00 GMT`, and the two obsolete forms a recipient must still accept: RFC 850 `Sunday, 06-Nov-94 08:49:37 GMT` (a two-digit year: 50 to 99 is 19xx, 00 to 49 is 20xx) and asctime `Sun Nov 6 08:49:37 1994` (space-padded day, taken as GMT). The weekday must match the date. Anything else: `Invalid`.