diff --git a/src/js.rs b/src/js.rs index 24df082e..daa45dce 100644 --- a/src/js.rs +++ b/src/js.rs @@ -377,6 +377,13 @@ extern { extern { pub type Date; + /// The toDateString() method returns the date portion of a Date object + /// in human readable form in American English. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString + #[wasm_bindgen(method, js_name = toDateString)] + pub fn to_date_string(this: &Date) -> JsString; + /// The toISOString() method returns a string in simplified extended ISO format (ISO /// 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or /// ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset, diff --git a/tests/all/js_globals/Date.rs b/tests/all/js_globals/Date.rs index 601a04ca..930c59df 100644 --- a/tests/all/js_globals/Date.rs +++ b/tests/all/js_globals/Date.rs @@ -2,6 +2,34 @@ use super::project; +#[test] +fn to_date_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_date_string(this: &Date) -> JsString { + this.to_date_string() + } + "#) + .file("test.ts", r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + let date = new Date(1993, 6, 28, 14, 39, 7); + + assert.equal(wasm.to_date_string(date), 'Wed Jul 28 1993'); + } + "#) + .test() +} + #[test] fn to_iso_string() { project() @@ -82,7 +110,7 @@ fn to_locale_date_string() { 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'); + assert.equal(wasm.to_locale_date_string(date, 'de-DE', options), 'Thursday, December 20, 2012'); } "#) .test()