elfo_core/time/
mod.rs

1use std::time::SystemTime;
2
3pub use self::{interval::Interval, stopwatch::Stopwatch};
4
5pub(crate) use r#impl::*;
6
7mod interval;
8mod stopwatch;
9
10#[cfg(test)]
11pub(crate) mod r#impl {
12    use std::{cell::Cell, time::Duration};
13
14    use super::*;
15
16    thread_local! {
17        pub(crate) static NOW: Cell<Duration> = Default::default();
18    }
19
20    pub(crate) fn advance(duration: Duration) {
21        NOW.with(|now| now.set(now.get() + duration))
22    }
23
24    pub(crate) fn now() -> SystemTime {
25        SystemTime::UNIX_EPOCH + NOW.with(Cell::get)
26    }
27}
28
29#[cfg(not(test))]
30pub(crate) mod r#impl {
31    use super::*;
32
33    #[inline]
34    pub(crate) fn now() -> SystemTime {
35        SystemTime::now()
36    }
37}