From a4d47afda6b31ac5bbf9d09cdc4b01cc7321649f Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 27 Jun 2018 09:41:16 +0200 Subject: [PATCH] feat(js) Implement the `Date.UTC` binding. --- src/js.rs | 9 +++++++++ tests/all/js_globals/Date.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/js.rs b/src/js.rs index 52eeedab4..405ea398f 100644 --- a/src/js.rs +++ b/src/js.rs @@ -516,6 +516,15 @@ extern { #[wasm_bindgen(method, js_name = toUTCString)] 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 /// a Date object. /// diff --git a/tests/all/js_globals/Date.rs b/tests/all/js_globals/Date.rs index 20c8ec348..32cadec05 100644 --- a/tests/all/js_globals/Date.rs +++ b/tests/all/js_globals/Date.rs @@ -304,6 +304,32 @@ fn to_utc_string() { .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] fn value_of() { project()