summaryrefslogtreecommitdiffstats
path: root/vendor/iana-time-zone/src/tz_wasm32.rs
blob: 69c36b5532a38d60c629dbd3166f16c7ffe77e7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use js_sys::{Array, Intl, Object, Reflect};
use wasm_bindgen::JsValue;

pub(crate) fn get_timezone_inner() -> Result<String, crate::GetTimezoneError> {
    let intl = Intl::DateTimeFormat::new(&Array::new(), &Object::new()).resolved_options();
    Reflect::get(&intl, &JsValue::from_str("timeZone"))
        .ok()
        .and_then(|tz| tz.as_string())
        .ok_or(crate::GetTimezoneError::OsError)
}

#[cfg(test)]
mod tests {
    use wasm_bindgen_test::*;

    #[wasm_bindgen_test]
    fn pass() {
        let tz = super::get_timezone_inner().unwrap();
        console_log!("tz={:?}", tz);
    }
}