diff --git a/Cargo.lock b/Cargo.lock index dd208d13c8..63c5f7e2d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -715,16 +715,16 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.26" +version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5" +checksum = "defd4e7873dbddba6c7c91e199c7fcb946abc4a6a4ac3195400bcfb01b5de877" dependencies = [ "android-tzdata", "iana-time-zone", "js-sys", "num-traits", "wasm-bindgen", - "winapi", + "windows-targets 0.48.1", ] [[package]] diff --git a/boa_engine/Cargo.toml b/boa_engine/Cargo.toml index 30bd248da8..f4221a6d5e 100644 --- a/boa_engine/Cargo.toml +++ b/boa_engine/Cargo.toml @@ -64,7 +64,7 @@ num-integer = "0.1.45" bitflags = "2.4.0" indexmap = "2.0.0" ryu-js = "0.2.2" -chrono = { version = "0.4.26", default-features = false, features = ["clock", "std"] } +chrono = { version = "0.4.30", default-features = false, features = ["clock", "std"] } fast-float = "0.2.0" once_cell = "1.18.0" tap = "1.0.1" diff --git a/boa_engine/src/context/hooks.rs b/boa_engine/src/context/hooks.rs index e6cd49c6be..182f0d91d6 100644 --- a/boa_engine/src/context/hooks.rs +++ b/boa_engine/src/context/hooks.rs @@ -174,7 +174,7 @@ pub trait HostHooks { /// Gets the current UTC time of the host. /// - /// Defaults to using [`Utc::now`] on all targets, which can cause panics if your platform + /// Defaults to using [`Utc::now`] on all targets, which can cause panics if the target /// doesn't support [`SystemTime::now`][time]. /// /// [time]: std::time::SystemTime::now @@ -184,25 +184,36 @@ pub trait HostHooks { /// Converts the naive datetime `utc` to the corresponding local datetime. /// - /// Defaults to using [`Local`] on all targets, which can cause panics if your platform + /// Defaults to using [`Local`] on all targets, which can cause panics if the taget /// doesn't support [`SystemTime::now`][time]. /// /// [time]: std::time::SystemTime::now fn local_from_utc(&self, utc: NaiveDateTime) -> DateTime { let offset = Local.offset_from_utc_datetime(&utc); - DateTime::from_utc(utc, offset) + offset.from_utc_datetime(&utc) } /// Converts the naive local datetime `local` to a local timezone datetime. /// - /// Defaults to using [`Local`] on all targets, which can cause panics if your platform + /// Defaults to using [`Local`] on all targets, which can cause panics if the target /// doesn't support [`SystemTime::now`][time]. /// /// [time]: std::time::SystemTime::now fn local_from_naive_local(&self, local: NaiveDateTime) -> LocalResult> { - Local - .offset_from_local_datetime(&local) - .map(|offset| DateTime::from_local(local, offset)) + match Local.offset_from_local_datetime(&local) { + LocalResult::None => LocalResult::None, + LocalResult::Single(offset) => offset.from_local_datetime(&local), + LocalResult::Ambiguous(earliest, latest) => { + match ( + earliest.from_local_datetime(&local).earliest(), + latest.from_local_datetime(&local).latest(), + ) { + (Some(earliest), Some(latest)) => LocalResult::Ambiguous(earliest, latest), + (Some(dt), None) | (None, Some(dt)) => LocalResult::Single(dt), + (None, None) => LocalResult::None, + } + } + } } } diff --git a/boa_wasm/Cargo.toml b/boa_wasm/Cargo.toml index e80ee0109e..2e10b57ed6 100644 --- a/boa_wasm/Cargo.toml +++ b/boa_wasm/Cargo.toml @@ -15,7 +15,7 @@ rust-version.workspace = true boa_engine.workspace = true wasm-bindgen = "0.2.87" getrandom = { version = "0.2.10", features = ["js"] } -chrono = { version = "0.4.26", default-features = false, features = ["clock", "std", "wasmbind"] } +chrono = { version = "0.4.30", default-features = false, features = ["clock", "std", "wasmbind"] } console_error_panic_hook = "0.1.7" [features]