simple_datetime_rs/utils/
crossplatform_util.rs

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