fedimint_core/
time.rs

1// nosemgrep: ban-system-time-now
2use std::time::SystemTime;
3
4#[cfg(not(target_family = "wasm"))]
5pub fn now() -> SystemTime {
6    // nosemgrep: ban-system-time-now
7    SystemTime::now()
8}
9
10#[cfg(target_family = "wasm")]
11pub fn now() -> SystemTime {
12    SystemTime::UNIX_EPOCH
13        + std::time::Duration::from_secs_f64(js_sys::Date::new_0().get_time() / 1000.)
14}
15
16/// Returns the duration since the Unix epoch
17pub fn duration_since_epoch() -> std::time::Duration {
18    now()
19        .duration_since(SystemTime::UNIX_EPOCH)
20        .expect("time to work")
21}