#[cfg(feature = "wasm")]
mod wasm_impl {
use wasm_bindgen::prelude::*;
use crate::{ZonedDateTime as Zdt, Duration};
#[wasm_bindgen]
pub struct WasmZonedDateTime {
inner: Zdt,
}
#[wasm_bindgen]
impl WasmZonedDateTime {
#[wasm_bindgen(js_name = now)]
pub fn now() -> WasmZonedDateTime {
WasmZonedDateTime { inner: Zdt::now() }
}
#[wasm_bindgen(js_name = fromISO)]
pub fn from_iso(s: &str) -> Result<WasmZonedDateTime, JsValue> {
Zdt::from_iso(s)
.map(|inner| WasmZonedDateTime { inner })
.map_err(|e| JsValue::from_str(&e.to_string()))
}
#[wasm_bindgen(getter)] pub fn year(&self) -> i32 { self.inner.year() }
#[wasm_bindgen(getter)] pub fn month(&self) -> u8 { self.inner.month() }
#[wasm_bindgen(getter)] pub fn day(&self) -> u8 { self.inner.day() }
#[wasm_bindgen(getter)] pub fn hour(&self) -> u8 { self.inner.hour() }
#[wasm_bindgen(getter)] pub fn minute(&self) -> u8 { self.inner.minute() }
#[wasm_bindgen(getter)] pub fn second(&self) -> u8 { self.inner.second() }
#[wasm_bindgen(js_name = plusDays)]
pub fn plus_days(&self, days: i32) -> WasmZonedDateTime {
WasmZonedDateTime { inner: self.inner.plus(Duration::days(days)) }
}
#[wasm_bindgen(js_name = minusDays)]
pub fn minus_days(&self, days: i32) -> WasmZonedDateTime {
WasmZonedDateTime { inner: self.inner.minus(Duration::days(days)) }
}
#[wasm_bindgen(js_name = inTimezone)]
pub fn in_timezone(&self, tz: &str) -> Result<WasmZonedDateTime, JsValue> {
self.inner
.in_timezone(tz)
.map(|inner| WasmZonedDateTime { inner })
.map_err(|e| JsValue::from_str(&e.to_string()))
}
#[wasm_bindgen(js_name = toISO)]
pub fn to_iso(&self) -> String {
self.inner.to_iso()
}
#[wasm_bindgen]
pub fn format(&self, fmt: &str) -> String {
self.inner.format(fmt)
}
}
}