mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-10 22:26:05 +00:00
Add date to iso string
This commit is contained in:
parent
8f21393c6b
commit
dd3e8cc8b8
@ -377,6 +377,15 @@ extern {
|
|||||||
extern {
|
extern {
|
||||||
pub type Date;
|
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.
|
/// 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
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON
|
||||||
|
@ -2,6 +2,34 @@
|
|||||||
|
|
||||||
use super::project;
|
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]
|
#[test]
|
||||||
fn to_json() {
|
fn to_json() {
|
||||||
project()
|
project()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user