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()