Fix wasm32 implementation of current_local_offset
This commit is contained in:
parent
311ff6bc31
commit
530e405103
14
src/lib.rs
14
src/lib.rs
|
@ -27,7 +27,11 @@ pub struct Instant(InnerInstant);
|
||||||
impl Instant {
|
impl Instant {
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
pub fn now() -> Instant {
|
pub fn now() -> Instant {
|
||||||
let stamp = web_sys::window().expect("cannot get window").performance().expect("cannot get performance").now();
|
let stamp = web_sys::window()
|
||||||
|
.expect("cannot get window")
|
||||||
|
.performance()
|
||||||
|
.expect("cannot get performance")
|
||||||
|
.now();
|
||||||
return Instant(Duration::seconds_f64(stamp / 1_000f64));
|
return Instant(Duration::seconds_f64(stamp / 1_000f64));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,9 +59,11 @@ impl std::ops::Sub for Instant {
|
||||||
#[cfg(feature = "local-offset")]
|
#[cfg(feature = "local-offset")]
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
pub fn current_local_offset() -> Result<time::UtcOffset, time::error::IndeterminateOffset> {
|
pub fn current_local_offset() -> Result<time::UtcOffset, time::error::IndeterminateOffset> {
|
||||||
// get_timezone_offset is in minutes
|
// The value returned by `getTimezoneOffset()` is inverted. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset#negative_values_and_positive_values.
|
||||||
time::UtcOffset::from_whole_seconds((js_sys::Date::new_0().get_timezone_offset() * 60f64) as i32)
|
time::UtcOffset::from_whole_seconds(
|
||||||
.map_err(|_| time::error::IndeterminateOffset)
|
(-js_sys::Date::new_0().get_timezone_offset() * 60f64) as i32,
|
||||||
|
)
|
||||||
|
.map_err(|_| time::error::IndeterminateOffset)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "local-offset")]
|
#[cfg(feature = "local-offset")]
|
||||||
|
|
Loading…
Reference in New Issue