feat(js) Implement the Date.now binding.

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

View File

@ -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.
///

View File

@ -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()