Skip to main content

Module clock

Module clock 

Source
Expand description

Centralised timestamp utilities.

Mirrors ~/src/graphrefly-ts/src/core/clock.ts and the Python core/clock.py. Convention: nanoseconds, _ns suffix, two clock domains (monotonic for ordering, wall-clock for attribution) per CLAUDE.md “Time utility rule.”

§Precision

  • monotonic_nsstd::time::Instant resolves to true nanoseconds on most modern platforms. Captured against a process-static origin (lazy via OnceLock) so values fit in u64 for ~584 years of process uptime.
  • wall_clock_nsSystemTime::now() - UNIX_EPOCH truncated to u64 nanoseconds; valid until ~2554. Beyond that, returns u64::MAX. Pre-epoch system clocks (rare misconfiguration) return 0.

Mixing the two clocks is a bug — durations belong in monotonic; user-visible timestamps belong in wall-clock. The Core dispatcher uses monotonic exclusively.

Functions§

monotonic_ns
Monotonic nanosecond timestamp.
wall_clock_ns
Wall-clock nanosecond timestamp (Unix epoch).