Rust

clock

Module

Time sources for the scheduler: the wall clock, and a test clock that stands still until advanced.

Contents

use utopia_schedule::SystemClock;
Rust
pub struct SystemClock

The wall clock, in UTC. Sleeping yields to the Tokio runtime.

use utopia_schedule::TestClock;
Rust
pub struct TestClock

A 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

The time source and sleeper of a Scheduler.

Isolating the clock is what makes timing defects testable: a scheduler driven by a TestClock can reproduce a tick phase sitting milliseconds before a minute boundary, the kind of state a wall clock only reaches in production.

Implemented byArcSystemClockTestClock