mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 10:10:52 +00:00
feat(js) Implement the Date.now
binding.
This commit is contained in:
parent
869d99b870
commit
e334c0c5af
@ -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.
|
||||
///
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user