mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-25 11:02:11 +03:00
feat(js) Implement the Date.UTC
binding.
This commit is contained in:
parent
e334c0c5af
commit
a4d47afda6
@ -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.
|
||||
///
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user