Add date to locale date string

This commit is contained in:
Sendil Kumar 2018-06-25 10:16:04 +02:00
parent 4e05bc470f
commit be44ad8ad8
2 changed files with 42 additions and 0 deletions

View File

@ -377,6 +377,18 @@ extern {
extern {
pub type Date;
/// The toLocaleDateString() method returns a string with a language sensitive
/// representation of the date portion of this date. The new locales and options
/// arguments let applications specify the language whose formatting conventions
/// should be used and allow to 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/toLocaleDateString
#[wasm_bindgen(method, js_name = toLocaleDateString)]
pub fn to_locale_date_string(this: &Date, locale: JsString, options: JsValue) -> JsString;
/// The toLocaleString() method returns a string with a language sensitive
/// representation of this date. The new locales and options arguments
/// let applications specify the language whose formatting conventions

View File

@ -2,6 +2,36 @@
use super::project;
#[test]
fn to_locale_date_string() {
project()
.file("src/lib.rs", r#"
#![feature(proc_macro, wasm_custom_section)]
extern crate wasm_bindgen;
use JsValue;
use wasm_bindgen::prelude::*;
use wasm_bindgen::js::{Date, JsString};
#[wasm_bindgen]
pub fn to_locale_date_string(this: &Date, locale: JsString, options: JsValue) -> JsString {
this.to_locale_date_string(locale, options)
}
"#)
.file("test.ts", r#"
import * as assert from "assert";
import * as wasm from "./out";
export function test() {
let date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
let options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
assert.equal(wasm.to_locale_date_string(date, 'de-DE', options), '2012 M12 20, Thu');
}
"#)
.test()
}
#[test]
fn to_locale_string() {
project()