Skip to main content

Module clock

Module clock 

Source
Expand description

Clock abstraction for testable time-dependent logic.

Code that needs the current time should accept a &dyn Clock instead of calling SystemTime::now() directly. Production callers pass SystemClock; tests pass MockClock and advance it explicitly.

Both now_unix_secs() (wall clock) and now_monotonic() (monotonic) are exposed because they have different uses:

  • wall clock for timestamps stored in the database (session expiry, createdAt)
  • monotonic for measuring elapsed time (rate-limiter windows, tick scheduling) — wall clock can jump backward via NTP

Structs§

MockClock
Test clock with manual advancement.
SystemClock
Clock backed by std::time — the production default.

Traits§

Clock