TimeSource

Trait TimeSource 

Source
pub trait TimeSource:
    Send
    + Sync
    + Debug {
    // Required methods
    fn now(&self) -> Instant;
    fn sleep(&self, duration: Duration);
    fn today_date_string(&self) -> String;

    // Provided method
    fn elapsed_since(&self, earlier: Instant) -> Duration { ... }
}
Expand description

Abstraction over time-related operations.

This trait allows production code to use real system time while tests can use a controllable mock implementation for fast, deterministic testing.

Required Methods§

Source

fn now(&self) -> Instant

Get the current instant for measuring elapsed time.

Source

fn sleep(&self, duration: Duration)

Sleep for the specified duration.

In tests, this may be a no-op or advance logical time.

Source

fn today_date_string(&self) -> String

Get today’s date as YYYY-MM-DD string.

Used for daily debouncing of telemetry/update checks.

Provided Methods§

Source

fn elapsed_since(&self, earlier: Instant) -> Duration

Calculate elapsed time since an earlier instant.

Implementors§