Skip to main content

made_core/ports/
clock.rs

1//! [`ClockPort`] — source of wall-clock time.
2//!
3//! The domain never calls `OffsetDateTime::now_utc` directly so that
4//! deliberations stay reproducible under test and deterministic
5//! clocks can be injected (frozen clocks for replay, accelerated
6//! clocks for load tests, etc.).
7
8use time::OffsetDateTime;
9
10use crate::value_objects::DurationMs;
11
12pub trait ClockPort: Send + Sync {
13    fn now(&self) -> OffsetDateTime;
14
15    /// Monotonic time since the composition root created this clock.
16    /// Deterministic test clocks default to a frozen zero uptime.
17    fn uptime(&self) -> DurationMs {
18        DurationMs::ZERO
19    }
20}