Add date to iso string

This commit is contained in:
Sendil Kumar 2018-06-25 10:16:58 +02:00
parent 8f21393c6b
commit dd3e8cc8b8
2 changed files with 38 additions and 1 deletions

View File

@ -377,6 +377,15 @@ extern {
extern {
pub type Date;
/// 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,
/// as denoted by the suffix "Z"
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
#[wasm_bindgen(method, js_name = toISOString)]
pub fn to_iso_string(this: &Date) -> JsString;
/// The toJSON() method returns a string representation of the Date object.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON

View File

@ -2,6 +2,34 @@
use super::project;
#[test]
fn to_iso_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_iso_string(this: &Date) -> JsString {
this.to_iso_string()
}
"#)
.file("test.ts", r#"
import * as assert from "assert";
import * as wasm from "./out";
export function test() {
let date = new Date('05 October 2011 14:48 UTC');
assert.equal(wasm.to_iso_string(date), '2011-10-05T14:48:00.000Z');
}
"#)
.test()
}
#[test]
fn to_json() {
project()