mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 18:20:51 +00:00
binding for Date.prototype.setFullYear()
This commit is contained in:
parent
1a8da45340
commit
d555b7f068
@ -1027,6 +1027,13 @@ extern "C" {
|
|||||||
#[wasm_bindgen(method, js_name = setDate)]
|
#[wasm_bindgen(method, js_name = setDate)]
|
||||||
pub fn set_date(this: &Date, day: u32) -> f64;
|
pub fn set_date(this: &Date, day: u32) -> f64;
|
||||||
|
|
||||||
|
/// The setFullYear() method sets the full year for a specified date according to local time.
|
||||||
|
/// Returns new timestamp.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear
|
||||||
|
#[wasm_bindgen(method, js_name = setFullYear)]
|
||||||
|
pub fn set_full_year(this: &Date, year: u32) -> f64;
|
||||||
|
|
||||||
/// The toDateString() method returns the date portion of a Date object
|
/// The toDateString() method returns the date portion of a Date object
|
||||||
/// in human readable form in American English.
|
/// in human readable form in American English.
|
||||||
///
|
///
|
||||||
|
@ -765,6 +765,45 @@ fn set_date() {
|
|||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn set_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 set_full_year(this: &Date, year: u32) -> f64 {
|
||||||
|
this.set_full_year(year)
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.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 19, 1976 23:15:30');
|
||||||
|
|
||||||
|
let eventMsFromUnixEpoch = wasm.set_full_year(event1, 1976);
|
||||||
|
|
||||||
|
assert.equal(eventMsFromUnixEpoch, 209312130000);
|
||||||
|
assert.equal(event1.getTime(), event2.valueOf());
|
||||||
|
assert.equal(event1.getFullYear(), 1976);
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.test()
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_date_string() {
|
fn to_date_string() {
|
||||||
project()
|
project()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user