iana_time_zone/
lib.rs
1#[cfg_attr(target_os = "linux", path = "tz_linux.rs")]
22#[cfg_attr(target_os = "windows", path = "tz_windows.rs")]
23#[cfg_attr(any(target_os = "macos", target_os = "ios"), path = "tz_macos.rs")]
24#[cfg_attr(
25 all(target_arch = "wasm32", not(target_os = "wasi")),
26 path = "tz_wasm32.rs"
27)]
28#[cfg_attr(
29 any(target_os = "freebsd", target_os = "dragonfly"),
30 path = "tz_freebsd.rs"
31)]
32#[cfg_attr(
33 any(target_os = "netbsd", target_os = "openbsd"),
34 path = "tz_netbsd.rs"
35)]
36#[cfg_attr(
37 any(target_os = "illumos", target_os = "solaris"),
38 path = "tz_illumos.rs"
39)]
40#[cfg_attr(target_os = "android", path = "tz_android.rs")]
41mod platform;
42
43#[derive(Debug)]
45pub enum GetTimezoneError {
46 FailedParsingString,
48 IoError(std::io::Error),
50 OsError,
52}
53
54impl std::error::Error for GetTimezoneError {
55 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
56 match self {
57 GetTimezoneError::FailedParsingString => None,
58 GetTimezoneError::IoError(err) => Some(err),
59 GetTimezoneError::OsError => None,
60 }
61 }
62}
63
64impl std::fmt::Display for GetTimezoneError {
65 fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
66 f.write_str(match self {
67 Self::FailedParsingString => "GetTimezoneError::FailedParsingString",
68 Self::IoError(err) => return err.fmt(f),
69 Self::OsError => "OsError",
70 })
71 }
72}
73
74impl std::convert::From<std::io::Error> for GetTimezoneError {
75 fn from(orig: std::io::Error) -> Self {
76 GetTimezoneError::IoError(orig)
77 }
78}
79
80#[inline]
85pub fn get_timezone() -> std::result::Result<String, crate::GetTimezoneError> {
86 platform::get_timezone_inner()
87}
88
89#[cfg(test)]
90mod tests {
91 use super::*;
92
93 #[test]
94 fn get_current() {
95 println!("current: {}", get_timezone().unwrap());
96 }
97}