diff --git a/src/js.rs b/src/js.rs index 6de22dfd..52eeedab 100644 --- a/src/js.rs +++ b/src/js.rs @@ -431,6 +431,13 @@ extern { #[wasm_bindgen(constructor)] pub fn new() -> Date; + /// The `Date.now()` method returns the number of milliseconds + /// elapsed since January 1, 1970 00:00:00 UTC. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now + #[wasm_bindgen(static_method_of = Date)] + pub fn now() -> Number; + /// The toDateString() method returns the date portion of a Date object /// in human readable form in American English. /// diff --git a/tests/all/js_globals/Date.rs b/tests/all/js_globals/Date.rs index 82ed7009..20c8ec34 100644 --- a/tests/all/js_globals/Date.rs +++ b/tests/all/js_globals/Date.rs @@ -28,6 +28,32 @@ fn new() { .test() } +#[test] +fn now() { + 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 now() -> Number { + Date::now() + } + "#) + .file("test.ts", r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + assert.equal(typeof wasm.now(), "number"); + } + "#) + .test() +} + #[test] fn to_date_string() { project()