Skip to main content

Module time

Module time 

Source
Expand description

Wall-clock “now” helpers.

The three-line SystemTime::now().duration_since(UNIX_EPOCH) body was re-implemented in 26 files across four crates before this module existed, with the only variation being the return type and whether a pre-epoch clock maps to 0 or unwrap_or_default() — which are the same thing (docs/reports/REPORT_DRY_AND_MODULARITY_AUDIT_2026_09_06.md §2.2).

Two integer widths are offered rather than one, because callers were split 16/8 between i64 (SQLite column types, JSON timestamps) and u64 (durations, comparisons against other u64s). Forcing one width would push a cast into every caller of the other; offering both keeps every existing call site’s type unchanged.

A clock set before the Unix epoch yields 0, never a panic — these are used on hot paths (every persisted event, every stats sample) where a panic on a misconfigured clock would be far worse than a zero timestamp.

Functions§

now_ms
Milliseconds since the Unix epoch, as i64.
now_ms_u64
Milliseconds since the Unix epoch, as u64.
now_secs
Seconds since the Unix epoch, as i64.
now_secs_u64
Seconds since the Unix epoch, as u64.