use std::sync::Arc;
use std::time::Duration;
use crate::tools::time_provider::time_provider::TimeProvider;
pub struct TimeProviderMokaClock {
time_provider: Arc<dyn TimeProvider>,
origin_millis: i64,
}
impl TimeProviderMokaClock {
pub fn new(time_provider: Arc<dyn TimeProvider>) -> Self {
let origin_millis = time_provider.current_time_millis().0;
Self { time_provider, origin_millis }
}
}
impl moka::ExternalClock for TimeProviderMokaClock {
fn elapsed_since_origin(&self) -> Duration {
let now = self.time_provider.current_time_millis().0;
Duration::from_millis(now.saturating_sub(self.origin_millis).max(0) as u64)
}
}