Skip to content

Commit a81827c

Browse files
committed
binding for Date.prototype.setMinutes()
1 parent 11a58a1 commit a81827c

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/js.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,12 @@ extern "C" {
10481048
#[wasm_bindgen(method, js_name = setMilliseconds)]
10491049
pub fn set_milliseconds(this: &Date, milliseconds: u32) -> f64;
10501050

1051+
/// The setMinutes() method sets the minutes for a specified date according to local time.
1052+
///
1053+
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMinutes
1054+
#[wasm_bindgen(method, js_name = setMinutes)]
1055+
pub fn set_minutes(this: &Date, minutes: u32) -> f64;
1056+
10511057
/// The toDateString() method returns the date portion of a Date object
10521058
/// in human readable form in American English.
10531059
///

tests/all/js_globals/Date.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,45 @@ fn set_milliseconds() {
880880
.test()
881881
}
882882

883+
#[test]
884+
fn set_minutes() {
885+
project()
886+
.file(
887+
"src/lib.rs",
888+
r#"
889+
#![feature(proc_macro, wasm_custom_section)]
890+
891+
extern crate wasm_bindgen;
892+
use wasm_bindgen::prelude::*;
893+
use wasm_bindgen::js::Date;
894+
895+
#[wasm_bindgen]
896+
pub fn set_minutes(this: &Date, minutes: u32) -> f64 {
897+
this.set_minutes(minutes)
898+
}
899+
"#,
900+
)
901+
.file(
902+
"test.js",
903+
r#"
904+
import * as assert from "assert";
905+
import * as wasm from "./out";
906+
907+
export function test() {
908+
let event1 = new Date('August 19, 1975 23:15:30');
909+
let event2 = new Date('August 19, 1975 23:45:30');
910+
911+
let eventMsFromUnixEpoch = wasm.set_minutes(event1, 45);
912+
913+
assert.equal(eventMsFromUnixEpoch, 177691530000);
914+
assert.equal(event1.getTime(), event2.valueOf());
915+
assert.equal(event1.getMinutes(), 45);
916+
}
917+
"#,
918+
)
919+
.test()
920+
}
921+
883922
#[test]
884923
fn to_date_string() {
885924
project()

0 commit comments

Comments
 (0)