mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-21 16:51:33 +00:00
binding for Date.prototype.getTimezoneOffset()
This commit is contained in:
@ -886,6 +886,13 @@ extern "C" {
|
|||||||
#[wasm_bindgen(method, js_name = getTime)]
|
#[wasm_bindgen(method, js_name = getTime)]
|
||||||
pub fn get_time(this: &Date) -> f64;
|
pub fn get_time(this: &Date) -> f64;
|
||||||
|
|
||||||
|
/// The getTimezoneOffset() method returns the time zone difference, in minutes,
|
||||||
|
/// from current locale (host system settings) to UTC.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset
|
||||||
|
#[wasm_bindgen(method, js_name = getTimezoneOffset)]
|
||||||
|
pub fn get_timezone_offset(this: &Date) -> f64;
|
||||||
|
|
||||||
/// Creates a JavaScript Date instance that represents
|
/// Creates a JavaScript Date instance that represents
|
||||||
/// a single moment in time. Date objects are based on a time value that is
|
/// a single moment in time. Date objects are based on a time value that is
|
||||||
/// the number of milliseconds since 1 January 1970 UTC.
|
/// the number of milliseconds since 1 January 1970 UTC.
|
||||||
|
@ -312,6 +312,42 @@ fn get_time() {
|
|||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn get_timezone_offset() {
|
||||||
|
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_timezone_offset(this: &Date) -> f64 {
|
||||||
|
this.get_timezone_offset()
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.file(
|
||||||
|
"test.js",
|
||||||
|
r#"
|
||||||
|
import * as assert from "assert";
|
||||||
|
import * as wasm from "./out";
|
||||||
|
|
||||||
|
export function test() {
|
||||||
|
let date1 = new Date('August 19, 1975 23:15:30 GMT+07:00');
|
||||||
|
let date2 = new Date('August 19, 1975 23:15:30 GMT-02:00');
|
||||||
|
|
||||||
|
assert.equal(typeof wasm.get_timezone_offset(date1), "number");
|
||||||
|
assert.equal(wasm.get_timezone_offset(date1), wasm.get_timezone_offset(date2));
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.test()
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn new() {
|
fn new() {
|
||||||
project()
|
project()
|
||||||
|
Reference in New Issue
Block a user