2022-02-27 23:25:12 -05:00
|
|
|
use time::OffsetDateTime;
|
|
|
|
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
2022-05-22 01:00:25 -04:00
|
|
|
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");
|
2022-02-27 23:25:12 -05:00
|
|
|
}
|
|
|
|
|
2022-05-22 01:00:25 -04:00
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
|
|
#[inline(always)]
|
2022-02-27 23:25:12 -05:00
|
|
|
pub fn now_utc() -> OffsetDateTime {
|
|
|
|
return OffsetDateTime::now_utc();
|
|
|
|
}
|
2022-05-22 01:15:16 -04:00
|
|
|
|
|
|
|
#[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()
|
|
|
|
}
|