binding for Date.prototype.setTime()

This commit is contained in:
toversus 2018-07-10 21:46:44 +09:00
parent c185897eff
commit 91d6ae5f04
2 changed files with 45 additions and 0 deletions

View File

@ -1066,6 +1066,13 @@ extern "C" {
#[wasm_bindgen(method, js_name = setSeconds)]
pub fn set_seconds(this: &Date, seconds: u32) -> f64;
/// The setTime() method sets the Date object to the time represented by a number of milliseconds
/// since January 1, 1970, 00:00:00 UTC.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setTime
#[wasm_bindgen(method, js_name = setTime)]
pub fn set_time(this: &Date, time: f64) -> f64;
/// The toDateString() method returns the date portion of a Date object
/// in human readable form in American English.
///

View File

@ -997,6 +997,44 @@ fn set_seconds() {
.test()
}
#[test]
fn set_time() {
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;
#[wasm_bindgen]
pub fn set_time(this: &Date, time: f64) -> f64 {
this.set_time(time)
}
"#,
)
.file(
"test.js",
r#"
import * as assert from "assert";
import * as wasm from "./out";
export function test() {
let event1 = new Date('July 1, 1999');
let event2 = new Date();
let eventMsFromUnixEpoch = wasm.set_time(event2, event1.getTime());
assert.equal(eventMsFromUnixEpoch, 930754800000);
assert.equal(event1.valueOf(), event2.getTime());
}
"#,
)
.test()
}
#[test]
fn to_date_string() {
project()