Skip to content

Commit

Permalink
Use js runtime for Local offset in js environment (chronotope#412)
Browse files Browse the repository at this point in the history
Possible fix for chronotope#411
  • Loading branch information
quodlibetor committed Jun 29, 2020
1 parent 0e0178a commit 8bc94d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Versions with only mechanical changes will be omitted from the following list.

* serde modules do a better job with `Option` types (#417 @mwkroening and #429
@fx-kirin)
* Use js runtime when using wasmbind to get the local offset (#412
@quodlibetor)

## 0.4.11

Expand Down
8 changes: 8 additions & 0 deletions src/offset/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ impl TimeZone for Local {
Date::from_utc(*utc, *midnight.offset())
}

#[cfg(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind"))]
fn from_utc_datetime(&self, utc: &NaiveDateTime) -> DateTime<Local> {
// Get the offset from the js runtime
let offset = FixedOffset::west((js_sys::Date::new_0().get_timezone_offset() as i32) * 60);
DateTime::from_utc(*utc, offset)
}

#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind")))]
fn from_utc_datetime(&self, utc: &NaiveDateTime) -> DateTime<Local> {
let timespec = datetime_to_timespec(utc, false);

Expand Down

0 comments on commit 8bc94d5

Please sign in to comment.