mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-25 11:02:11 +03:00
Add date to locale time string
This commit is contained in:
parent
ca17ef8d7c
commit
c0aba821d5
11
src/js.rs
11
src/js.rs
@ -376,6 +376,17 @@ extern {
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
pub type Date;
|
||||
|
||||
/// The toLocaleTimeString() method returns a string with a language sensitive
|
||||
/// representation of the time portion of this date. The new locales and options
|
||||
/// arguments let applications specify the language whose formatting conventions should be
|
||||
/// used and customize the behavior of the function. In older implementations, which ignore
|
||||
/// the locales and options arguments, the locale used and the form of the string
|
||||
/// returned are entirely implementation dependent.
|
||||
///
|
||||
/// 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: JsString) -> JsString;
|
||||
|
||||
/// The toString() method returns a string representing
|
||||
/// the specified Date object.
|
||||
|
@ -2,6 +2,33 @@
|
||||
|
||||
use super::project;
|
||||
|
||||
#[test]
|
||||
fn to_locale_time_string() {
|
||||
project()
|
||||
.file("src/lib.rs", r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::js::{Date, JsString};
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn to_locale_time_string(this: &Date, locale: JsString) -> JsString {
|
||||
this.to_locale_time_string(locale)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
let date = new Date('August 19, 1975 23:15:30');
|
||||
assert.equal(wasm.to_locale_time_string(date, 'en-US'), "11:15:30 PM");
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn to_string() {
|
||||
project()
|
||||
|
Loading…
Reference in New Issue
Block a user