clock
ModuleTime sources for the scheduler: the wall clock, and a test clock that stands still until advanced.
Contents
Structs
SystemClockThe wall clock, in UTC. Sleeping yields to the Tokio runtime.TestClockA deterministic clock for tests: time stands still until advanced, and sleeping advances it instead of blocking. Sub-second phases (a tick starting 59 milliseconds before a minute boundary, a 60 second sleep that resumes 1.5 milliseconds late) become exact, repeatable fixtures.use utopia_schedule::SystemClock;Rust
pub struct SystemClockThe wall clock, in UTC. Sleeping yields to the Tokio runtime.
use utopia_schedule::TestClock;Rust
pub struct TestClockA deterministic clock for tests: time stands still until advanced, and sleeping advances it instead of blocking. Sub-second phases (a tick starting 59 milliseconds before a minute boundary, a 60 second sleep that resumes 1.5 milliseconds late) become exact, repeatable fixtures.
Share it with the scheduler through an Arc to advance it from the
test.
Rust
use php_std::datetime::{DateTime, Timestamp, TzInfo};
use utopia_schedule::{Clock, TestClock};
let start = DateTime::parse(b"2026-08-17 15:59:59.941", None, &TzInfo::utc(), Timestamp { sec: 0, usec: 0 }).unwrap();
let clock = TestClock::new(&start);
clock.advance(0.059);
assert_eq!(clock.now()?.format(b"H:i:s.u"), b"16:00:00.000000");use utopia_schedule::Clock;Rust
pub trait Clock: Send + Sync