Expand description
§ppoppo-clock
The time port of the ppoppo ecosystem: one Clock (“what time is it?”) and
one Timer (“wake me in N ms”), injected wherever code needs time, so no
surface reads the ambient system clock directly.
use ppoppo_clock::ArcClock;
fn stamp(clock: &ArcClock) -> i64 {
clock.now_unix_millis()
}| Feature | Arm |
|---|---|
native | native::{WallClock, TokioTimer, system_tz} — the Tokio runtime |
wasm | wasm::{WasmClock, WasmTimer, browser_local_tz} — the browser event loop |
mock | mock::{FrozenClock, MockClock, AdvanceableTimer, frozen_at, mock_pair} — deterministic tests |
With no feature the crate is the two traits and their Arc aliases — no
runtime, no IO. The port’s value types are jiff’s
(Timestamp, Zoned, tz::TimeZone, civil::Date), re-exported as
ppoppo_clock::jiff so a consumer names one version of them.
STABLE VOCABULARY. Nameable by any application, semver-versioned on its
own: the port’s signature changes only on a major version. Every ppoppo
face takes and returns these traits, so a consumer holding an
ArcClock built here hands the same value to each face.
§The port
A single deep module hiding the time source from every consumer. Three
impl arms, each behind a feature: native (Tokio), wasm
(js_sys::Date + an Intl time-zone-name probe + Window.setTimeout),
mock (frozen and advanceable clocks plus a timer driven by them). Zone
math is arm-independent: jiff’s bundled tzdb makes Clock::now_in and
Clock::today_in provided methods, so each arm implements only
Clock::now.
Standards: STS_TIME_MECHANICS.md §“Universal client + server time port”.
Inside the ppoppo workspace the xtask CLOCK-PORT rule refuses an ambient
time source outside this crate.
§Temporal alignment
jiff is the Rust realization of the TC39 Temporal model (Timestamp ≙
Temporal.Instant, Zoned ≙ Temporal.ZonedDateTime, civil::Date ≙
Temporal.PlainDate, tz::TimeZone ≙ Temporal.TimeZone), identically
on every arm.
Re-exports§
pub use jiff;
Modules§
- mock
- Deterministic test arm: a frozen clock, a settable clock, and a timer whose sleeps resolve only when that clock is advanced.
- native
- Tokio arm: the system wall clock and a Tokio-backed timer.
- wasm
- Browser arm:
Date.now()as the clock andWindow.setTimeoutas the timer.
Traits§
- Clock
- Wall-clock readouts. Single port for “what time is it?” across all surfaces.
- Timer
- Async scheduling primitive. Single port for “wait N ms” / “yield event-loop tick”.