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