Skip to main content

ClockProvider

Trait ClockProvider 

Source
pub trait ClockProvider: Send + Sync {
    // Required method
    fn now(&self) -> DateTime<Utc>;
}
Expand description

Provides the current wall-clock time, injectable for testing.

Implement this trait to decouple domain logic from Utc::now(). Use SystemClock in production and MockClock (from auths-test-utils) in tests.

Usage:

fn check_expiry(clock: &dyn ClockProvider, expires_at: DateTime<Utc>) -> bool {
    clock.now() < expires_at
}

Required Methods§

Source

fn now(&self) -> DateTime<Utc>

Returns the current time.

Usage:

let now = clock.now();

Implementors§