From 2e85bbd9e01dc51a35f4780f3e7c6e28cbf6aca4 Mon Sep 17 00:00:00 2001 From: toversus Date: Mon, 9 Jul 2018 18:04:20 +0900 Subject: [PATCH] binding for Date.prototype.getUTCMinutes() --- src/js.rs | 6 ++++++ tests/all/js_globals/Date.rs | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/js.rs b/src/js.rs index 82708b94..f0c9d6bf 100644 --- a/src/js.rs +++ b/src/js.rs @@ -926,6 +926,12 @@ extern "C" { #[wasm_bindgen(method, js_name = getUTCMilliseconds)] pub fn get_utc_milliseconds(this: &Date) -> u32; + /// The getUTCMinutes() method returns the minutes in the specified date according to universal time. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMinutes + #[wasm_bindgen(method, js_name = getUTCMinutes)] + pub fn get_utc_minutes(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. diff --git a/tests/all/js_globals/Date.rs b/tests/all/js_globals/Date.rs index 05860c19..29c24d6b 100755 --- a/tests/all/js_globals/Date.rs +++ b/tests/all/js_globals/Date.rs @@ -526,6 +526,42 @@ fn get_utc_milliseconds() { .test() } +#[test] +fn get_utc_minutes() { + 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_minutes(this: &Date) -> u32 { + this.get_utc_minutes() + } + "#, + ) + .file( + "test.js", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + let date1 = new Date('1 January 2000 03:15:30 GMT+07:00'); + let date2 = new Date('1 January 2000 03:15:30 GMT+03:30'); + + assert.equal(wasm.get_utc_minutes(date1), 15); + assert.equal(wasm.get_utc_minutes(date2), 45); + } + "#, + ) + .test() +} + #[test] fn new() { project()