mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-25 11:02:11 +03:00
Add date to iso string
This commit is contained in:
parent
8f21393c6b
commit
dd3e8cc8b8
11
src/js.rs
11
src/js.rs
@ -376,7 +376,16 @@ extern {
|
||||
#[wasm_bindgen]
|
||||
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
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user