#[cfg_attr(target_os = "linux", path = "tz_linux.rs")]
#[cfg_attr(target_os = "windows", path = "tz_windows.rs")]
#[cfg_attr(target_os = "macos", path = "tz_macos.rs")]
#[cfg_attr(
all(target_arch = "wasm32", not(target_os = "wasi")),
path = "tz_wasm32.rs"
)]
#[cfg_attr(
any(target_os = "freebsd", target_os = "dragonfly"),
path = "tz_freebsd.rs"
)]
#[cfg_attr(
any(target_os = "netbsd", target_os = "openbsd"),
path = "tz_netbsd.rs"
)]
mod platform;
#[derive(Debug)]
pub enum GetTimezoneError {
FailedParsingString,
IoError(std::io::Error),
OsError,
}
impl std::error::Error for GetTimezoneError {}
impl std::fmt::Display for GetTimezoneError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
use GetTimezoneError::*;
let descr = match self {
FailedParsingString => "GetTimezoneError::FailedParsingString",
IoError(_) => "GetTimezoneError::IoError(_)",
OsError => "OsError",
};
write!(f, "{}", descr)
}
}
impl std::convert::From<std::io::Error> for GetTimezoneError {
fn from(orig: std::io::Error) -> Self {
GetTimezoneError::IoError(orig)
}
}
pub fn get_timezone() -> std::result::Result<String, crate::GetTimezoneError> {
platform::get_timezone_inner()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn get_current() {
println!("current: {}", get_timezone().unwrap());
}
}