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
#[cfg(not(target_family = "wasm"))] use std::time::SystemTime; #[cfg(target_family = "wasm")] use wasm_bindgen::prelude::*; pub(crate) fn now_seconds() -> u64 { (now_milliseconds() / 1000) as u64 } #[cfg(not(target_family = "wasm"))] pub(crate) fn now_milliseconds() -> u128 { SystemTime::now() .duration_since(std::time::UNIX_EPOCH) .unwrap() .as_millis() } #[cfg(target_family = "wasm")] #[wasm_bindgen] extern "C" { #[wasm_bindgen(js_namespace = Date, js_name = now)] fn wasm_date_now() -> f64; } #[cfg(target_family = "wasm")] pub(crate) fn now_milliseconds() -> u128 { wasm_date_now() as u128 }