From 33edc256a778d87d78e2492ba5213898c32d4ebf Mon Sep 17 00:00:00 2001 From: Paul Hansen Date: Fri, 27 Dec 2024 12:25:39 -0600 Subject: [PATCH 1/4] Add options parameter to `Date.to_locale_time_string` --- crates/js-sys/CHANGELOG.md | 6 ++++++ crates/js-sys/src/lib.rs | 2 +- crates/js-sys/tests/wasm/Date.rs | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/js-sys/CHANGELOG.md b/crates/js-sys/CHANGELOG.md index 5a4de395eeb..c93b5c76b4b 100644 --- a/crates/js-sys/CHANGELOG.md +++ b/crates/js-sys/CHANGELOG.md @@ -1,6 +1,12 @@ # `js-sys` Change Log -------------------------------------------------------------------------------- +## Unreleased + +### Changed + +* Added `options` parameter to `Date.to_local_time_string` + [#4384](https://github.com/rustwasm/wasm-bindgen/pull/4384) ## 0.2.1 diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index 459e4d93953..d0ead3a4cb5 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -3390,7 +3390,7 @@ extern "C" { /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString) #[wasm_bindgen(method, js_name = toLocaleTimeString)] - pub fn to_locale_time_string(this: &Date, locale: &str) -> JsString; + pub fn to_locale_time_string(this: &Date, locale: &str, options: &JsValue) -> JsString; /// The `toString()` method returns a string representing /// the specified Date object. diff --git a/crates/js-sys/tests/wasm/Date.rs b/crates/js-sys/tests/wasm/Date.rs index 484498d4739..0a224093e56 100644 --- a/crates/js-sys/tests/wasm/Date.rs +++ b/crates/js-sys/tests/wasm/Date.rs @@ -484,7 +484,7 @@ fn to_locale_string() { fn to_locale_time_string() { let date = Date::new(&"August 19, 1975 23:15:30".into()); assert_eq!( - JsValue::from(date.to_locale_time_string("en-US")), + JsValue::from(date.to_locale_time_string("en-US", &JsValue::undefined())), "11:15:30 PM", ); } From 4daced24456f6fd4519af065372939458303c6f2 Mon Sep 17 00:00:00 2001 From: Paul Hansen Date: Sat, 4 Jan 2025 14:14:20 -0600 Subject: [PATCH 2/4] Add separate binding for to_locale_time_string_with_options --- crates/js-sys/CHANGELOG.md | 4 ++-- crates/js-sys/src/lib.rs | 5 ++++- crates/js-sys/tests/wasm/Date.rs | 6 +++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/js-sys/CHANGELOG.md b/crates/js-sys/CHANGELOG.md index c93b5c76b4b..7728cc11981 100644 --- a/crates/js-sys/CHANGELOG.md +++ b/crates/js-sys/CHANGELOG.md @@ -3,9 +3,9 @@ -------------------------------------------------------------------------------- ## Unreleased -### Changed +### Added -* Added `options` parameter to `Date.to_local_time_string` +* Added bindings to `Date.to_locale_time_string_with_options` [#4384](https://github.com/rustwasm/wasm-bindgen/pull/4384) ## 0.2.1 diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index d0ead3a4cb5..852dd9e1a13 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -3390,7 +3390,10 @@ extern "C" { /// /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString) #[wasm_bindgen(method, js_name = toLocaleTimeString)] - pub fn to_locale_time_string(this: &Date, locale: &str, options: &JsValue) -> JsString; + pub fn to_locale_time_string(this: &Date, locale: &str) -> JsString; + + #[wasm_bindgen(method, js_name = toLocaleTimeString)] + pub fn to_locale_time_string_with_options(this: &Date, locale: &str, options: &JsValue) -> JsString; /// The `toString()` method returns a string representing /// the specified Date object. diff --git a/crates/js-sys/tests/wasm/Date.rs b/crates/js-sys/tests/wasm/Date.rs index 0a224093e56..16ccb3f1529 100644 --- a/crates/js-sys/tests/wasm/Date.rs +++ b/crates/js-sys/tests/wasm/Date.rs @@ -484,7 +484,11 @@ fn to_locale_string() { fn to_locale_time_string() { let date = Date::new(&"August 19, 1975 23:15:30".into()); assert_eq!( - JsValue::from(date.to_locale_time_string("en-US", &JsValue::undefined())), + JsValue::from(date.to_locale_time_string("en-US")), + "11:15:30 PM", + ); + assert_eq!( + JsValue::from(date.to_locale_time_string_with_options("en-US", &JsValue::undefined())), "11:15:30 PM", ); } From b1130479100422f114f5b728bb942f6bddc037c3 Mon Sep 17 00:00:00 2001 From: Paul Hansen Date: Sat, 4 Jan 2025 14:17:33 -0600 Subject: [PATCH 3/4] cargo fmt --- crates/js-sys/src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index 852dd9e1a13..ac1d51bfadd 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -3393,7 +3393,11 @@ extern "C" { pub fn to_locale_time_string(this: &Date, locale: &str) -> JsString; #[wasm_bindgen(method, js_name = toLocaleTimeString)] - pub fn to_locale_time_string_with_options(this: &Date, locale: &str, options: &JsValue) -> JsString; + pub fn to_locale_time_string_with_options( + this: &Date, + locale: &str, + options: &JsValue, + ) -> JsString; /// The `toString()` method returns a string representing /// the specified Date object. From 0a46290ae89faedb4726f2b58f6c6866b745acf0 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Tue, 7 Jan 2025 09:56:59 +0100 Subject: [PATCH 4/4] Move changelog entry --- CHANGELOG.md | 3 +++ crates/js-sys/CHANGELOG.md | 6 ------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16bd83de8e0..f144ab366c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ * Add `--list`, `--ignored`, `--exact` and `--nocapture` to `wasm-bindgen-test-runner`, analogous to `cargo test`. [#4356](https://github.com/rustwasm/wasm-bindgen/pull/4356) +* Add bindings to `Date.to_locale_time_string_with_options`. + [#4384](https://github.com/rustwasm/wasm-bindgen/pull/4384) + ### Changed * Optional parameters are now typed as `T | undefined | null` to reflect the actual JS behavior. diff --git a/crates/js-sys/CHANGELOG.md b/crates/js-sys/CHANGELOG.md index 7728cc11981..5a4de395eeb 100644 --- a/crates/js-sys/CHANGELOG.md +++ b/crates/js-sys/CHANGELOG.md @@ -1,12 +1,6 @@ # `js-sys` Change Log -------------------------------------------------------------------------------- -## Unreleased - -### Added - -* Added bindings to `Date.to_locale_time_string_with_options` - [#4384](https://github.com/rustwasm/wasm-bindgen/pull/4384) ## 0.2.1