File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -1066,6 +1066,13 @@ extern "C" {
1066
1066
#[ wasm_bindgen( method, js_name = setSeconds) ]
1067
1067
pub fn set_seconds ( this : & Date , seconds : u32 ) -> f64 ;
1068
1068
1069
+ /// The setTime() method sets the Date object to the time represented by a number of milliseconds
1070
+ /// since January 1, 1970, 00:00:00 UTC.
1071
+ ///
1072
+ /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setTime
1073
+ #[ wasm_bindgen( method, js_name = setTime) ]
1074
+ pub fn set_time ( this : & Date , time : f64 ) -> f64 ;
1075
+
1069
1076
/// The toDateString() method returns the date portion of a Date object
1070
1077
/// in human readable form in American English.
1071
1078
///
Original file line number Diff line number Diff line change @@ -997,6 +997,44 @@ fn set_seconds() {
997
997
. test ( )
998
998
}
999
999
1000
+ #[ test]
1001
+ fn set_time ( ) {
1002
+ project ( )
1003
+ . file (
1004
+ "src/lib.rs" ,
1005
+ r#"
1006
+ #![feature(proc_macro, wasm_custom_section)]
1007
+
1008
+ extern crate wasm_bindgen;
1009
+ use wasm_bindgen::prelude::*;
1010
+ use wasm_bindgen::js::Date;
1011
+
1012
+ #[wasm_bindgen]
1013
+ pub fn set_time(this: &Date, time: f64) -> f64 {
1014
+ this.set_time(time)
1015
+ }
1016
+ "# ,
1017
+ )
1018
+ . file (
1019
+ "test.js" ,
1020
+ r#"
1021
+ import * as assert from "assert";
1022
+ import * as wasm from "./out";
1023
+
1024
+ export function test() {
1025
+ let event1 = new Date('July 1, 1999');
1026
+ let event2 = new Date();
1027
+
1028
+ let eventMsFromUnixEpoch = wasm.set_time(event2, event1.getTime());
1029
+
1030
+ assert.equal(eventMsFromUnixEpoch, 930754800000);
1031
+ assert.equal(event1.valueOf(), event2.getTime());
1032
+ }
1033
+ "# ,
1034
+ )
1035
+ . test ( )
1036
+ }
1037
+
1000
1038
#[ test]
1001
1039
fn to_date_string ( ) {
1002
1040
project ( )
You can’t perform that action at this time.
0 commit comments