simple_datetime_rs/utils/
crossplatform_util.rs1#[cfg(not(target_family="wasm"))]
2use std::time::SystemTime;
3#[cfg(target_family="wasm")]
4use wasm_bindgen::prelude::*;
5
6pub fn now_seconds() -> u64 {
7 (now_milliseconds() / 1000) as u64
8}
9
10#[cfg(not(target_family="wasm"))]
11pub fn now_milliseconds() -> u128 {
12 SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_millis()
13}
14
15#[cfg(target_family="wasm")]
16#[wasm_bindgen] extern "C" { #[wasm_bindgen(js_namespace = Date, js_name = now)] fn wasm_date_now() -> f64; }
17
18#[cfg(target_family="wasm")]
19pub fn now_milliseconds() -> u128 {
20 wasm_date_now() as u128
21}