binding for Date.prototype.getUTCHours()

This commit is contained in:
toversus 2018-07-09 17:54:19 +09:00
parent 975818a1f6
commit 6aa3661e11
2 changed files with 42 additions and 0 deletions

View File

@ -913,6 +913,12 @@ extern "C" {
#[wasm_bindgen(method, js_name = getUTCFullYear)]
pub fn get_utc_full_year(this: &Date) -> u32;
/// The getUTCHours() method returns the hours in the specified date according to universal time.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCHours
#[wasm_bindgen(method, js_name = getUTCHours)]
pub fn get_utc_hours(this: &Date) -> u32;
/// Creates a JavaScript Date instance that represents
/// a single moment in time. Date objects are based on a time value that is
/// the number of milliseconds since 1 January 1970 UTC.

View File

@ -456,6 +456,42 @@ fn get_utc_full_year() {
.test()
}
#[test]
fn get_utc_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 get_utc_hours(this: &Date) -> u32 {
this.get_utc_hours()
}
"#,
)
.file(
"test.js",
r#"
import * as assert from "assert";
import * as wasm from "./out";
export function test() {
let date1 = new Date('December 31, 1975, 23:15:30 GMT+11:00');
let date2 = new Date('December 31, 1975, 23:15:30 GMT-11:00');
assert.equal(wasm.get_utc_hours(date1), 12);
assert.equal(wasm.get_utc_hours(date2), 10);
}
"#,
)
.test()
}
#[test]
fn new() {
project()