binding for Date.prototype.setDate()

This commit is contained in:
toversus 2018-07-10 20:38:54 +09:00
parent f2f2d7231a
commit 1a8da45340
2 changed files with 45 additions and 0 deletions

View File

@ -1021,6 +1021,12 @@ extern "C" {
#[wasm_bindgen(static_method_of = Date)]
pub fn parse(date: JsString) -> f64;
/// The setDate() method sets the day of the Date object relative to the beginning of the currently set month.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setDate
#[wasm_bindgen(method, js_name = setDate)]
pub fn set_date(this: &Date, day: u32) -> f64;
/// The toDateString() method returns the date portion of a Date object
/// in human readable form in American English.
///

View File

@ -726,6 +726,45 @@ fn parse() {
.test()
}
#[test]
fn set_date() {
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_date(this: &Date, day: u32) -> f64 {
this.set_date(day)
}
"#,
)
.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 24, 1975 23:15:30');
let eventMsFromUnixEpoch = wasm.set_date(event1, 24);
assert.equal(eventMsFromUnixEpoch, 178121730000);
assert.equal(event1.getTime(), event2.valueOf());
assert.equal(event1.getDate(), 24);
}
"#,
)
.test()
}
#[test]
fn to_date_string() {
project()