Skip to main content

origin_domain/
clock.rs

1//! Time as a port.
2//!
3//! Domain code never calls `OffsetDateTime::now_utc()` directly — otherwise anything
4//! involving backoff, TTL or scheduling becomes untestable.
5
6use std::fmt::Debug;
7use time::OffsetDateTime;
8
9pub trait Clock: Debug + Send + Sync + 'static {
10    fn now(&self) -> OffsetDateTime;
11}
12
13/// The real system clock, in UTC.
14#[derive(Debug, Clone, Copy, Default)]
15pub struct SystemClock;
16
17impl Clock for SystemClock {
18    fn now(&self) -> OffsetDateTime {
19        OffsetDateTime::now_utc()
20    }
21}