1 use std::sync::LazyLock;
2 use std::time::{Duration, SystemTime, SystemTimeError};
3 
4 pub static NOW: LazyLock<SystemTime> = LazyLock::new(SystemTime::now);
5 
6 #[derive(PartialOrd, PartialEq, Ord, Eq)]
7 pub struct SystemTimeStub(SystemTime);
8 
9 impl SystemTimeStub {
now() -> Self10     pub fn now() -> Self {
11         Self(*NOW)
12     }
13 
checked_add(&self, duration: Duration) -> Option<Self>14     pub fn checked_add(&self, duration: Duration) -> Option<Self> {
15         self.0.checked_add(duration).map(|t| t.into())
16     }
17 
duration_since(&self, earlier: SystemTime) -> Result<Duration, SystemTimeError>18     pub fn duration_since(&self, earlier: SystemTime) -> Result<Duration, SystemTimeError> {
19         self.0.duration_since(earlier)
20     }
21 }
22 
23 impl From<SystemTime> for SystemTimeStub {
from(time: SystemTime) -> Self24     fn from(time: SystemTime) -> Self {
25         Self(time)
26     }
27 }
28