pub use klauthed_core::time::{Clock, Duration, FixedClock, Timestamp};
pub fn fixed_clock(unix_millis: i64) -> FixedClock {
FixedClock::at_unix_millis(unix_millis)
}
pub fn epoch_clock() -> FixedClock {
fixed_clock(0)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn fixed_clock_pins_and_advances() {
let clock = fixed_clock(1_000);
let t0 = clock.now();
assert_eq!(t0.unix_millis(), 1_000);
assert_eq!(clock.now(), t0);
clock.advance(Duration::seconds(2));
assert_eq!(clock.now().duration_since(t0).whole_seconds(), 2);
}
#[test]
fn epoch_clock_starts_at_zero() {
let clock = epoch_clock();
assert_eq!(clock.now().unix_millis(), 0);
}
#[test]
fn usable_behind_dyn_clock() {
let clock: std::sync::Arc<dyn Clock> = std::sync::Arc::new(fixed_clock(42));
assert_eq!(clock.now().unix_millis(), 42);
}
}