feat(js) Implement the Date.UTC binding.

This commit is contained in:
Ivan Enderlin 2018-06-27 09:41:16 +02:00
parent e334c0c5af
commit a4d47afda6
No known key found for this signature in database
GPG Key ID: 461F31FCE31F4AAD
2 changed files with 35 additions and 0 deletions

View File

@ -516,6 +516,15 @@ extern {
#[wasm_bindgen(method, js_name = toUTCString)] #[wasm_bindgen(method, js_name = toUTCString)]
pub fn to_utc_string(this: &Date) -> JsString; pub fn to_utc_string(this: &Date) -> JsString;
/// The `Date.UTC()` method accepts the same parameters as the
/// longest form of the constructor, and returns the number of
/// milliseconds in a `Date` object since January 1, 1970,
/// 00:00:00, universal time.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC
#[wasm_bindgen(static_method_of = Date, js_name = UTC)]
pub fn utc(year: Number, month: Number) -> Number;
/// The valueOf() method returns the primitive value of /// The valueOf() method returns the primitive value of
/// a Date object. /// a Date object.
/// ///

View File

@ -304,6 +304,32 @@ fn to_utc_string() {
.test() .test()
} }
#[test]
fn utc() {
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, Number};
#[wasm_bindgen]
pub fn utc() -> Number {
Date::utc(Number::new(JsValue::from(2018)), Number::new(JsValue::from(6)))
}
"#)
.file("test.ts", r#"
import * as assert from "assert";
import * as wasm from "./out";
export function test() {
assert.equal(wasm.utc(), 1530403200000);
}
"#)
.test()
}
#[test] #[test]
fn value_of() { fn value_of() {
project() project()