From 609d457301013ea7f6d274e51e925a687d30b70d Mon Sep 17 00:00:00 2001 From: toversus Date: Tue, 10 Jul 2018 21:27:12 +0900 Subject: [PATCH] binding for Date.prototype.setMonth() --- src/js.rs | 6 ++++++ tests/all/js_globals/Date.rs | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/js.rs b/src/js.rs index 9e26fce37..5ba80eed4 100644 --- a/src/js.rs +++ b/src/js.rs @@ -1054,6 +1054,12 @@ extern "C" { #[wasm_bindgen(method, js_name = setMinutes)] pub fn set_minutes(this: &Date, minutes: u32) -> f64; + /// The setMonth() method sets the month for a specified date according to the currently set year. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMonth + #[wasm_bindgen(method, js_name = setMonth)] + pub fn set_month(this: &Date, month: u32) -> f64; + /// The toDateString() method returns the date portion of a Date object /// in human readable form in American English. /// diff --git a/tests/all/js_globals/Date.rs b/tests/all/js_globals/Date.rs index f7252b21d..11ebcc7fb 100755 --- a/tests/all/js_globals/Date.rs +++ b/tests/all/js_globals/Date.rs @@ -919,6 +919,45 @@ fn set_minutes() { .test() } +#[test] +fn set_month() { + 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_month(this: &Date, month: u32) -> f64 { + this.set_month(month) + } + "#, + ) + .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('April 19, 1975 23:15:30'); + + let eventMsFromUnixEpoch = wasm.set_month(event1, 3); + + assert.equal(eventMsFromUnixEpoch, 167148930000); + assert.equal(event1.getTime(), event2.valueOf()); + assert.equal(event1.getMonth(), 3); + } + "#, + ) + .test() +} + #[test] fn to_date_string() { project()