2022-02-27 23:25:12 -05:00
|
|
|
use time::OffsetDateTime;
|
|
|
|
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
#[wasm_bindgen::prelude::wasm_bindgen(inline_js = r#"
|
|
|
|
export function unix_millis_now() {
|
|
|
|
return Date.now();
|
|
|
|
}"#)]
|
|
|
|
extern "C" {
|
|
|
|
fn unix_millis_now() -> f64;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn now_utc() -> OffsetDateTime {
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
2022-03-06 12:28:06 -05:00
|
|
|
return OffsetDateTime::from_unix_timestamp_nanos((unix_millis_now() * 1_000_000f64) as i128)
|
|
|
|
.expect("time outside supported range");
|
2022-02-27 23:25:12 -05:00
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
|
|
return OffsetDateTime::now_utc();
|
|
|
|
}
|