binding for Date.prototype.setHours()

This commit is contained in:
toversus 2018-07-10 20:51:39 +09:00
parent d555b7f068
commit 524628e1e1
2 changed files with 47 additions and 0 deletions

View File

@ -1034,6 +1034,14 @@ extern "C" {
#[wasm_bindgen(method, js_name = setFullYear)]
pub fn set_full_year(this: &Date, year: u32) -> f64;
/// The setHours() method sets the hours for a specified date according to local time,
/// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time represented
/// by the updated Date instance.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours
#[wasm_bindgen(method, js_name = setHours)]
pub fn set_hours(this: &Date, hours: u32) -> f64;
/// The toDateString() method returns the date portion of a Date object
/// in human readable form in American English.
///

View File

@ -804,6 +804,45 @@ fn set_full_year() {
.test()
}
#[test]
fn set_hours() {
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_hours(this: &Date, hours: u32) -> f64 {
this.set_hours(hours)
}
"#,
)
.file(
"test.js",
r#"
import * as assert from "assert";
import * as wasm from "./out";
export function test() {
let event1 = new Date('August 19, 1975 23:15:30');
let event2 = new Date('August 19, 1975 20:15:30');
let eventMsFromUnixEpoch = wasm.set_hours(event1, 20);
assert.equal(eventMsFromUnixEpoch, 177678930000);
assert.equal(event1.getTime(), event2.valueOf());
assert.equal(event1.getHours(), 20);
}
"#,
)
.test()
}
#[test]
fn to_date_string() {
project()