use std::time::{SystemTime, UNIX_EPOCH};
pub(crate) fn now_ms() -> u64 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default()
.as_millis() as u64
}
#[cfg(test)]
mod tests {
use super::now_ms;
#[test]
fn now_ms_returns_recent_epoch_millis() {
let observed = now_ms();
let upper = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.expect("system clock is after the unix epoch")
.as_millis() as u64;
assert!(
observed > 1_700_000_000_000,
"now_ms() should be a recent epoch-millis value, got {observed}"
);
assert!(
observed <= upper,
"now_ms() ({observed}) must not exceed a fresh reading ({upper})"
);
}
}