29 lines
970 B
Rust
29 lines
970 B
Rust
use time::OffsetDateTime;
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
pub fn now_utc() -> OffsetDateTime {
|
|
return OffsetDateTime::from_unix_timestamp_nanos((js_sys::Date::now() * 1_000_000f64) as i128)
|
|
.expect("current time outside supported range");
|
|
}
|
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
#[inline(always)]
|
|
pub fn now_utc() -> OffsetDateTime {
|
|
return OffsetDateTime::now_utc();
|
|
}
|
|
|
|
#[cfg(feature = "local-offset")]
|
|
#[cfg(target_arch = "wasm32")]
|
|
pub fn current_local_offset() -> Result<time::UtcOffset, time::error::IndeterminateOffset> {
|
|
// get_timezone_offset is in minutes
|
|
time::UtcOffset::from_whole_seconds((js_sys::Date::new_0().get_timezone_offset() * 60f64) as i32)
|
|
.map_err(|_| time::error::IndeterminateOffset)
|
|
}
|
|
|
|
#[cfg(feature = "local-offset")]
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
#[inline(always)]
|
|
pub fn current_local_offset() -> Result<time::UtcOffset, time::error::IndeterminateOffset> {
|
|
time::UtcOffset::current_local_offset()
|
|
}
|