From 3007e813eaef5cafd47d21ed3010b5da922c4b7a Mon Sep 17 00:00:00 2001 From: toversus Date: Wed, 4 Jul 2018 19:41:06 +0900 Subject: [PATCH 1/2] bindings for Date.prototype.getDay() --- src/js.rs | 7 +++++++ tests/all/js_globals/Date.rs | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/js.rs b/src/js.rs index 38293d924..75ab69d20 100644 --- a/src/js.rs +++ b/src/js.rs @@ -663,6 +663,13 @@ extern "C" { extern "C" { pub type Date; + /// The getDay() method returns the day of the week for the specified date according to local time, + /// where 0 represents Sunday. For the day of the month see getDate(). + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay + #[wasm_bindgen(method, js_name = getDay)] + pub fn get_day(this: &Date) -> Number; + /// 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 6a8a66f1f..863620ff0 100644 --- a/tests/all/js_globals/Date.rs +++ b/tests/all/js_globals/Date.rs @@ -2,6 +2,40 @@ use super::project; +#[test] +fn get_day() { + 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, Number}; + + #[wasm_bindgen] + pub fn get_day(this: &Date) -> Number { + this.get_day() + } + "#, + ) + .file( + "test.ts", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + let date = new Date('August 19, 1975 23:15:30'); + + assert.equal(wasm.get_day(date), 2); + } + "#, + ) + .test() +} + #[test] fn new() { project() From e95994fd19b58b3f6a8c34a02a80df89800f97c2 Mon Sep 17 00:00:00 2001 From: toversus Date: Wed, 4 Jul 2018 19:52:12 +0900 Subject: [PATCH 2/2] bindings for Date.prototype.getFullYear() --- 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 75ab69d20..793308057 100644 --- a/src/js.rs +++ b/src/js.rs @@ -670,6 +670,12 @@ extern "C" { #[wasm_bindgen(method, js_name = getDay)] pub fn get_day(this: &Date) -> Number; + /// The getFullYear() method returns the year of the specified date according to local time. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getFullYear + #[wasm_bindgen(method, js_name = getFullYear)] + pub fn get_full_year(this: &Date) -> Number; + /// 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 863620ff0..c7751c523 100644 --- a/tests/all/js_globals/Date.rs +++ b/tests/all/js_globals/Date.rs @@ -36,6 +36,42 @@ fn get_day() { .test() } +#[test] +fn get_full_year() { + 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, Number}; + + #[wasm_bindgen] + pub fn get_full_year(this: &Date) -> Number { + this.get_full_year() + } + "#, + ) + .file( + "test.ts", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + let date = new Date('July 20, 1969 00:20:18'); + let abbrDate = new Date('Thu, 06 Sep 12 00:00:00'); + + assert.equal(wasm.get_full_year(date), 1969); + assert.equal(wasm.get_full_year(abbrDate), 2012); + } + "#, + ) + .test() +} + #[test] fn new() { project()