Skip to content

Commit

Permalink
Add binding for Date.to_locale_time_string_with_options (#4384)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-hansen authored Jan 7, 2025
1 parent 24f20ae commit d59de5c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions crates/js-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3392,6 +3392,13 @@ extern "C" {
#[wasm_bindgen(method, js_name = toLocaleTimeString)]
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.
///
Expand Down
4 changes: 4 additions & 0 deletions crates/js-sys/tests/wasm/Date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,10 @@ fn to_locale_time_string() {
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",
);
}

#[wasm_bindgen_test]
Expand Down

0 comments on commit d59de5c

Please sign in to comment.