mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-23 01:31:34 +00:00
bindings for Date.prototype.setUTCXXX() (#456)
This commit is contained in:
committed by
Alex Crichton
parent
77b86f481e
commit
5ce424e57b
46
src/js.rs
46
src/js.rs
@ -1082,6 +1082,52 @@ extern "C" {
|
|||||||
#[wasm_bindgen(method, js_name = setTime)]
|
#[wasm_bindgen(method, js_name = setTime)]
|
||||||
pub fn set_time(this: &Date, time: f64) -> f64;
|
pub fn set_time(this: &Date, time: f64) -> f64;
|
||||||
|
|
||||||
|
/// The setUTCDate() method sets the day of the month for a specified date
|
||||||
|
/// according to universal time.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCDate
|
||||||
|
#[wasm_bindgen(method, js_name = setUTCDate)]
|
||||||
|
pub fn set_utc_date(this: &Date, day: u32) -> f64;
|
||||||
|
|
||||||
|
/// The setUTCFullYear() method sets the full year for a specified date according to universal time.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear
|
||||||
|
#[wasm_bindgen(method, js_name = setUTCFullYear)]
|
||||||
|
pub fn set_utc_full_year(this: &Date, year: u32) -> f64;
|
||||||
|
|
||||||
|
/// The setUTCHours() method sets the hour for a specified date according to universal time,
|
||||||
|
/// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time
|
||||||
|
/// represented by the updated Date instance.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCHours
|
||||||
|
#[wasm_bindgen(method, js_name = setUTCHours)]
|
||||||
|
pub fn set_utc_hours(this: &Date, hours: u32) -> f64;
|
||||||
|
|
||||||
|
/// The setUTCMilliseconds() method sets the milliseconds for a specified date
|
||||||
|
/// according to universal time.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMilliseconds
|
||||||
|
#[wasm_bindgen(method, js_name = setUTCMilliseconds)]
|
||||||
|
pub fn set_utc_milliseconds(this: &Date, milliseconds: u32) -> f64;
|
||||||
|
|
||||||
|
/// The setUTCMinutes() method sets the minutes for a specified date according to universal time.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMinutes
|
||||||
|
#[wasm_bindgen(method, js_name = setUTCMinutes)]
|
||||||
|
pub fn set_utc_minutes(this: &Date, minutes: u32) -> f64;
|
||||||
|
|
||||||
|
/// The setUTCMonth() method sets the month for a specified date according to universal time.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMonth
|
||||||
|
#[wasm_bindgen(method, js_name = setUTCMonth)]
|
||||||
|
pub fn set_utc_month(this: &Date, month: u32) -> f64;
|
||||||
|
|
||||||
|
/// The setUTCSeconds() method sets the seconds for a specified date according to universal time.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCSeconds
|
||||||
|
#[wasm_bindgen(method, js_name = setUTCSeconds)]
|
||||||
|
pub fn set_utc_seconds(this: &Date, seconds: 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.
|
||||||
///
|
///
|
||||||
|
@ -1035,6 +1035,279 @@ fn set_time() {
|
|||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn set_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 set_utc_date(this: &Date, day: u32) -> f64 {
|
||||||
|
this.set_utc_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 GMT-3:00');
|
||||||
|
let event2 = new Date('August 19, 1975 02:15:30 GMT');
|
||||||
|
|
||||||
|
let eventMsFromUnixEpoch = wasm.set_utc_date(event1, 19);
|
||||||
|
|
||||||
|
assert.equal(eventMsFromUnixEpoch, event2.getTime());
|
||||||
|
assert.equal(event1.getTime(), event2.valueOf());
|
||||||
|
assert.equal(event1.getUTCDate(), 19);
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.test()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn set_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 set_utc_full_year(this: &Date, year: u32) -> f64 {
|
||||||
|
this.set_utc_full_year(year)
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.file(
|
||||||
|
"test.js",
|
||||||
|
r#"
|
||||||
|
import * as assert from "assert";
|
||||||
|
import * as wasm from "./out";
|
||||||
|
|
||||||
|
export function test() {
|
||||||
|
let event1 = new Date('December 31, 1975 23:15:30 GMT-3:00');
|
||||||
|
let event2 = new Date('January 01, 1975 02:15:30 GMT');
|
||||||
|
|
||||||
|
let eventMsFromUnixEpoch = wasm.set_utc_full_year(event1, 1975);
|
||||||
|
|
||||||
|
assert.equal(eventMsFromUnixEpoch, event2.getTime());
|
||||||
|
assert.equal(event1.getTime(), event2.valueOf());
|
||||||
|
assert.equal(event1.getUTCFullYear(), 1975);
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.test()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn set_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 set_utc_hours(this: &Date, hours: u32) -> f64 {
|
||||||
|
this.set_utc_hours(hours)
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.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 GMT-3:00');
|
||||||
|
let event2 = new Date('August 20, 1975 23:15:30 GMT');
|
||||||
|
|
||||||
|
let eventMsFromUnixEpoch = wasm.set_utc_hours(event1, 23);
|
||||||
|
|
||||||
|
assert.equal(eventMsFromUnixEpoch, event2.getTime());
|
||||||
|
assert.equal(event1.getTime(), event2.valueOf());
|
||||||
|
assert.equal(event1.getUTCHours(), 23);
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.test()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn set_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 set_utc_milliseconds(this: &Date, milliseconds: u32) -> f64 {
|
||||||
|
this.set_utc_milliseconds(milliseconds)
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.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 GMT-3:00');
|
||||||
|
let event2 = new Date('August 20, 1975 02:15:30.420Z GMT');
|
||||||
|
|
||||||
|
let eventMsFromUnixEpoch = wasm.set_utc_milliseconds(event1, 420);
|
||||||
|
|
||||||
|
assert.equal(eventMsFromUnixEpoch, event2.getTime());
|
||||||
|
assert.equal(event1.getTime(), event2.valueOf());
|
||||||
|
assert.equal(event1.getUTCMilliseconds(), 420);
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.test()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn set_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 set_utc_minutes(this: &Date, minutes: u32) -> f64 {
|
||||||
|
this.set_utc_minutes(minutes)
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.file(
|
||||||
|
"test.js",
|
||||||
|
r#"
|
||||||
|
import * as assert from "assert";
|
||||||
|
import * as wasm from "./out";
|
||||||
|
|
||||||
|
export function test() {
|
||||||
|
let event1 = new Date('December 31, 1975, 23:15:30 GMT-3:00');
|
||||||
|
let event2 = new Date('January 01, 1976 02:25:30 GMT');
|
||||||
|
|
||||||
|
let eventMsFromUnixEpoch = wasm.set_utc_minutes(event1, 25);
|
||||||
|
|
||||||
|
assert.equal(eventMsFromUnixEpoch, event2.getTime());
|
||||||
|
assert.equal(event1.getTime(), event2.valueOf());
|
||||||
|
assert.equal(event1.getUTCMinutes(), 25);
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.test()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn set_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 set_utc_month(this: &Date, minutes: u32) -> f64 {
|
||||||
|
this.set_utc_month(minutes)
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.file(
|
||||||
|
"test.js",
|
||||||
|
r#"
|
||||||
|
import * as assert from "assert";
|
||||||
|
import * as wasm from "./out";
|
||||||
|
|
||||||
|
export function test() {
|
||||||
|
let event1 = new Date('December 31, 1975 23:15:30 GMT-3:00');
|
||||||
|
let event2 = new Date('December 01, 1976 02:15:30 GMT');
|
||||||
|
|
||||||
|
let eventMsFromUnixEpoch = wasm.set_utc_month(event1, 11);
|
||||||
|
|
||||||
|
assert.equal(eventMsFromUnixEpoch, event2.getTime());
|
||||||
|
assert.equal(event1.getTime(), event2.valueOf());
|
||||||
|
assert.equal(event1.getUTCMonth(), 11);
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.test()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn set_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 set_utc_seconds(this: &Date, seconds: u32) -> f64 {
|
||||||
|
this.set_utc_seconds(seconds)
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.file(
|
||||||
|
"test.js",
|
||||||
|
r#"
|
||||||
|
import * as assert from "assert";
|
||||||
|
import * as wasm from "./out";
|
||||||
|
|
||||||
|
export function test() {
|
||||||
|
let event1 = new Date('December 31, 1975 23:15:30 GMT-3:00');
|
||||||
|
let event2 = new Date('January 01, 1976 02:15:39 GMT');
|
||||||
|
|
||||||
|
let eventMsFromUnixEpoch = wasm.set_utc_seconds(event1, 39);
|
||||||
|
|
||||||
|
assert.equal(eventMsFromUnixEpoch, event2.getTime());
|
||||||
|
assert.equal(event1.getTime(), event2.valueOf());
|
||||||
|
assert.equal(event1.getUTCSeconds(), 39);
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.test()
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_date_string() {
|
fn to_date_string() {
|
||||||
project()
|
project()
|
||||||
|
Reference in New Issue
Block a user