Skip to content

Commit

Permalink
Add separate binding for to_locale_time_string_with_options
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-hansen committed Jan 4, 2025
1 parent 33edc25 commit 4daced2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions crates/js-sys/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion crates/js-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion crates/js-sys/tests/wasm/Date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
}
Expand Down

0 comments on commit 4daced2

Please sign in to comment.