Skip to main content

rite_runtime/
clock.rs

1//! The ceremony clock: the single source of wall-clock time for the run.
2//!
3//! Event time is part of the hashed transcript line, so it is audit evidence.
4//! It is owned by the executor (the authority on what happened), not by the
5//! transcript sink (a swappable persistence detail): the same `at` the sink
6//! writes is the `at` the live frontend sees, and it does not change if the
7//! storage backend changes. Reading the clock is the one nondeterministic input
8//! in the record path, so it lives behind this trait and can be faked in tests.
9
10use chrono::{DateTime, Utc};
11
12/// Source of wall-clock time for a ceremony run.
13///
14/// Implementations must be cheap to call (read once per emitted fact) and
15/// thread-safe: the executor runs on its own thread and shares the clock with
16/// the [`Reporter`](crate::Reporter).
17pub trait Clock: Send + Sync {
18    /// The current instant, in UTC.
19    fn now(&self) -> DateTime<Utc>;
20}
21
22/// The real clock: reads the host wall clock via [`Utc::now`]. The default for
23/// every production run.
24#[derive(Debug, Clone, Copy, Default)]
25pub struct SystemClock;
26
27impl Clock for SystemClock {
28    fn now(&self) -> DateTime<Utc> {
29        Utc::now()
30    }
31}