use std::time::{SystemTime, UNIX_EPOCH};
#[must_use]
pub(crate) fn unix_now_ms() -> u64 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.map_or(0, |elapsed| {
u64::try_from(elapsed.as_millis()).unwrap_or(u64::MAX)
})
}
#[cfg(test)]
#[cfg_attr(coverage_nightly, coverage(off))]
mod tests {
use super::*;
const WELL_BEFORE_NOW_MS: u64 = 1_577_836_800_000;
const WELL_AFTER_NOW_MS: u64 = 4_102_444_800_000;
#[test]
#[cfg_attr(miri, ignore)] fn the_clock_reads_a_plausible_present() {
let now = unix_now_ms();
assert!(now > WELL_BEFORE_NOW_MS, "{now} is not a present-day clock");
assert!(now < WELL_AFTER_NOW_MS, "{now} is not a present-day clock");
}
}