mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-25 11:02:11 +03:00
Add date to date string
fix failing test case
This commit is contained in:
parent
dd3e8cc8b8
commit
f9ae7f49ad
@ -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,
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user