From d3a17d40140719d635cc07e944618e7057f56fd2 Mon Sep 17 00:00:00 2001 From: toversus Date: Mon, 9 Jul 2018 17:38:38 +0900 Subject: [PATCH 1/9] binding for Date.prototype.getTimezoneOffset() --- src/js.rs | 7 +++++++ tests/all/js_globals/Date.rs | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/js.rs b/src/js.rs index 96ddd28e..54be3aec 100644 --- a/src/js.rs +++ b/src/js.rs @@ -886,6 +886,13 @@ extern "C" { #[wasm_bindgen(method, js_name = getTime)] pub fn get_time(this: &Date) -> f64; + /// The getTimezoneOffset() method returns the time zone difference, in minutes, + /// from current locale (host system settings) to UTC. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset + #[wasm_bindgen(method, js_name = getTimezoneOffset)] + pub fn get_timezone_offset(this: &Date) -> f64; + /// 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 b649f409..697b9d6f 100755 --- a/tests/all/js_globals/Date.rs +++ b/tests/all/js_globals/Date.rs @@ -312,6 +312,42 @@ fn get_time() { .test() } +#[test] +fn get_timezone_offset() { + 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_timezone_offset(this: &Date) -> f64 { + this.get_timezone_offset() + } + "#, + ) + .file( + "test.js", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + let date1 = new Date('August 19, 1975 23:15:30 GMT+07:00'); + let date2 = new Date('August 19, 1975 23:15:30 GMT-02:00'); + + assert.equal(typeof wasm.get_timezone_offset(date1), "number"); + assert.equal(wasm.get_timezone_offset(date1), wasm.get_timezone_offset(date2)); + } + "#, + ) + .test() +} + #[test] fn new() { project() From 792baefc221076232a6b85e460a10933e18989f2 Mon Sep 17 00:00:00 2001 From: toversus Date: Mon, 9 Jul 2018 17:42:30 +0900 Subject: [PATCH 2/9] binding for Date.prototype.getUTCDate() --- src/js.rs | 7 +++++++ tests/all/js_globals/Date.rs | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/js.rs b/src/js.rs index 54be3aec..ea85e37b 100644 --- a/src/js.rs +++ b/src/js.rs @@ -893,6 +893,13 @@ extern "C" { #[wasm_bindgen(method, js_name = getTimezoneOffset)] pub fn get_timezone_offset(this: &Date) -> f64; + /// The getUTCDate() method returns the day (date) of the month in the specified date + /// according to universal time. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDate + #[wasm_bindgen(method, js_name = getUTCDate)] + pub fn get_utc_date(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 697b9d6f..5f5c449a 100755 --- a/tests/all/js_globals/Date.rs +++ b/tests/all/js_globals/Date.rs @@ -348,6 +348,42 @@ fn get_timezone_offset() { .test() } +#[test] +fn get_utc_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 get_utc_date(this: &Date) -> u32 { + this.get_utc_date() + } + "#, + ) + .file( + "test.js", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + let date1 = new Date('August 19, 1975 23:15:30 GMT+11:00'); + let date2 = new Date('August 19, 1975 23:15:30 GMT-11:00'); + + assert.equal(wasm.get_utc_date(date1), 19); + assert.equal(wasm.get_utc_date(date2), 20); + } + "#, + ) + .test() +} + #[test] fn new() { project() From ea198486917009d12885b022bb7f595d4306ee63 Mon Sep 17 00:00:00 2001 From: toversus Date: Mon, 9 Jul 2018 17:46:21 +0900 Subject: [PATCH 3/9] binding for Date.prototype.getUTCDay() --- src/js.rs | 7 +++++++ tests/all/js_globals/Date.rs | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/js.rs b/src/js.rs index ea85e37b..253bb16e 100644 --- a/src/js.rs +++ b/src/js.rs @@ -900,6 +900,13 @@ extern "C" { #[wasm_bindgen(method, js_name = getUTCDate)] pub fn get_utc_date(this: &Date) -> u32; + /// The getUTCDay() method returns the day of the week in the specified date according to universal time, + /// where 0 represents Sunday. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDay + #[wasm_bindgen(method, js_name = getUTCDay)] + pub fn get_utc_day(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 5f5c449a..b61cfe5b 100755 --- a/tests/all/js_globals/Date.rs +++ b/tests/all/js_globals/Date.rs @@ -384,6 +384,42 @@ fn get_utc_date() { .test() } +#[test] +fn get_utc_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; + + #[wasm_bindgen] + pub fn get_utc_day(this: &Date) -> u32 { + this.get_utc_day() + } + "#, + ) + .file( + "test.js", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + let date1 = new Date('August 19, 1975 23:15:30 GMT+11:00'); + let date2 = new Date('August 19, 1975 23:15:30 GMT-11:00'); + + assert.equal(wasm.get_utc_day(date1), 2); + assert.equal(wasm.get_utc_day(date2), 3); + } + "#, + ) + .test() +} + #[test] fn new() { project() From 975818a1f658e52cb7c39d5613ccc73d2bf5b890 Mon Sep 17 00:00:00 2001 From: toversus Date: Mon, 9 Jul 2018 17:50:13 +0900 Subject: [PATCH 4/9] binding for Date.prototype.getUTCFullYear() --- 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 253bb16e..3bbc1efb 100644 --- a/src/js.rs +++ b/src/js.rs @@ -907,6 +907,12 @@ extern "C" { #[wasm_bindgen(method, js_name = getUTCDay)] pub fn get_utc_day(this: &Date) -> u32; + /// The getUTCFullYear() method returns the year in the specified date according to universal time. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCFullYear + #[wasm_bindgen(method, js_name = getUTCFullYear)] + pub fn get_utc_full_year(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 b61cfe5b..e0f11869 100755 --- a/tests/all/js_globals/Date.rs +++ b/tests/all/js_globals/Date.rs @@ -420,6 +420,42 @@ fn get_utc_day() { .test() } +#[test] +fn get_utc_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; + + #[wasm_bindgen] + pub fn get_utc_full_year(this: &Date) -> u32 { + this.get_utc_full_year() + } + "#, + ) + .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_full_year(date1), 1975); + assert.equal(wasm.get_utc_full_year(date2), 1976); + } + "#, + ) + .test() +} + #[test] fn new() { project() From 6aa3661e111fe646b3a33d11b10f8381b7542154 Mon Sep 17 00:00:00 2001 From: toversus Date: Mon, 9 Jul 2018 17:54:19 +0900 Subject: [PATCH 5/9] binding for Date.prototype.getUTCHours() --- 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 3bbc1efb..2eabf6cf 100644 --- a/src/js.rs +++ b/src/js.rs @@ -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. diff --git a/tests/all/js_globals/Date.rs b/tests/all/js_globals/Date.rs index e0f11869..98f6d38e 100755 --- a/tests/all/js_globals/Date.rs +++ b/tests/all/js_globals/Date.rs @@ -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() From c260ac7c3e362521c5899fd63bc274665fb74daa Mon Sep 17 00:00:00 2001 From: toversus Date: Mon, 9 Jul 2018 17:59:15 +0900 Subject: [PATCH 6/9] binding for Date.prototype.getUTCMilliseconds() --- 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 2eabf6cf..82708b94 100644 --- a/src/js.rs +++ b/src/js.rs @@ -919,6 +919,13 @@ extern "C" { #[wasm_bindgen(method, js_name = getUTCHours)] pub fn get_utc_hours(this: &Date) -> u32; + /// The getUTCMilliseconds() method returns the milliseconds in the specified date + /// according to universal time. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMilliseconds + #[wasm_bindgen(method, js_name = getUTCMilliseconds)] + pub fn get_utc_milliseconds(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 98f6d38e..05860c19 100755 --- a/tests/all/js_globals/Date.rs +++ b/tests/all/js_globals/Date.rs @@ -492,6 +492,40 @@ fn get_utc_hours() { .test() } +#[test] +fn get_utc_milliseconds() { + 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_milliseconds(this: &Date) -> u32 { + this.get_utc_milliseconds() + } + "#, + ) + .file( + "test.js", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + let date = new Date('2018-01-02T03:04:05.678Z'); + + assert.equal(wasm.get_utc_milliseconds(date), 678); + } + "#, + ) + .test() +} + #[test] fn new() { project() From 2e85bbd9e01dc51a35f4780f3e7c6e28cbf6aca4 Mon Sep 17 00:00:00 2001 From: toversus Date: Mon, 9 Jul 2018 18:04:20 +0900 Subject: [PATCH 7/9] 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() From 15d9f743ec92da25e9c287300bab1075c617ff02 Mon Sep 17 00:00:00 2001 From: toversus Date: Mon, 9 Jul 2018 18:08:38 +0900 Subject: [PATCH 8/9] binding for Date.prototype.getUTCMonth() --- src/js.rs | 7 +++++++ tests/all/js_globals/Date.rs | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/js.rs b/src/js.rs index f0c9d6bf..9ee03e18 100644 --- a/src/js.rs +++ b/src/js.rs @@ -932,6 +932,13 @@ extern "C" { #[wasm_bindgen(method, js_name = getUTCMinutes)] pub fn get_utc_minutes(this: &Date) -> u32; + /// The getUTCMonth() returns the month of the specified date according to universal time, + /// as a zero-based value (where zero indicates the first month of the year). + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMonth + #[wasm_bindgen(method, js_name = getUTCMonth)] + pub fn get_utc_month(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 29c24d6b..946aa7a9 100755 --- a/tests/all/js_globals/Date.rs +++ b/tests/all/js_globals/Date.rs @@ -562,6 +562,42 @@ fn get_utc_minutes() { .test() } +#[test] +fn get_utc_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 get_utc_month(this: &Date) -> u32 { + this.get_utc_month() + } + "#, + ) + .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_month(date1), 11); + assert.equal(wasm.get_utc_month(date2), 0); + } + "#, + ) + .test() +} + #[test] fn new() { project() From 5bfde7778d570e7cff54b0daa88acd5e53e44900 Mon Sep 17 00:00:00 2001 From: toversus Date: Mon, 9 Jul 2018 18:20:04 +0900 Subject: [PATCH 9/9] binding for Date.prototype.getUTCSeconds() --- src/js.rs | 6 ++++++ tests/all/js_globals/Date.rs | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/js.rs b/src/js.rs index 9ee03e18..6246197f 100644 --- a/src/js.rs +++ b/src/js.rs @@ -939,6 +939,12 @@ extern "C" { #[wasm_bindgen(method, js_name = getUTCMonth)] pub fn get_utc_month(this: &Date) -> u32; + /// The getUTCSeconds() method returns the seconds in the specified date according to universal time. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCSeconds + #[wasm_bindgen(method, js_name = getUTCSeconds)] + pub fn get_utc_seconds(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 946aa7a9..b6cf0dab 100755 --- a/tests/all/js_globals/Date.rs +++ b/tests/all/js_globals/Date.rs @@ -598,6 +598,40 @@ fn get_utc_month() { .test() } +#[test] +fn get_utc_seconds() { + 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_seconds(this: &Date) -> u32 { + this.get_utc_seconds() + } + "#, + ) + .file( + "test.js", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + let date = new Date('July 20, 1969, 20:18:04 UTC'); + + assert.equal(wasm.get_utc_seconds(date), 4); + } + "#, + ) + .test() +} + #[test] fn new() { project()