1#[cfg(not(feature = "tz-system"))]
2pub(crate) use self::disabled::*;
3#[cfg(feature = "tz-system")]
4pub(crate) use self::enabled::*;
5
6#[cfg(not(feature = "tz-system"))]
7mod disabled {
8 #[derive(Clone, Debug)]
9 pub(crate) enum Error {}
10
11 impl core::fmt::Display for Error {
12 fn fmt(&self, _: &mut core::fmt::Formatter) -> core::fmt::Result {
13 unreachable!()
14 }
15 }
16}
17
18#[cfg(feature = "tz-system")]
19mod enabled {
20 use crate::error;
21
22 #[derive(Clone, Debug)]
23 pub(crate) enum Error {
24 FailedEnvTz,
25 FailedEnvTzAsTzif,
26 FailedPosixTzAndUtf8,
27 FailedSystemTimeZone,
28 FailedUnnamedTzifInvalid,
29 FailedUnnamedTzifRead,
30 #[cfg(windows)]
31 WindowsMissingIanaMapping,
32 #[cfg(windows)]
33 WindowsTimeZoneKeyName,
34 #[cfg(windows)]
35 WindowsUtf16DecodeInvalid,
36 #[cfg(windows)]
37 WindowsUtf16DecodeNul,
38 }
39
40 impl From<Error> for error::Error {
41 #[cold]
42 #[inline(never)]
43 fn from(err: Error) -> error::Error {
44 error::ErrorKind::TzSystem(err).into()
45 }
46 }
47
48 impl error::IntoError for Error {
49 fn into_error(self) -> error::Error {
50 self.into()
51 }
52 }
53
54 impl core::fmt::Display for Error {
55 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
56 use self::Error::*;
57
58 match *self {
59 FailedEnvTz => f.write_str(
60 "`TZ` environment variable set, but failed to read value",
61 ),
62 FailedEnvTzAsTzif => f.write_str(
63 "failed to read `TZ` environment variable value \
64 as a TZif file after attempting (and failing) a tzdb \
65 lookup for that same value",
66 ),
67 FailedPosixTzAndUtf8 => f.write_str(
68 "failed to parse `TZ` environment variable as either \
69 a POSIX time zone transition string or as valid UTF-8",
70 ),
71 FailedSystemTimeZone => {
72 f.write_str("failed to find system time zone")
73 }
74 FailedUnnamedTzifInvalid => f.write_str(
75 "found invalid TZif data in unnamed time zone file",
76 ),
77 FailedUnnamedTzifRead => f.write_str(
78 "failed to read TZif data from unnamed time zone file",
79 ),
80 #[cfg(windows)]
81 WindowsMissingIanaMapping => f.write_str(
82 "found Windows time zone name, \
83 but could not find a mapping for it to an \
84 IANA time zone name",
85 ),
86 #[cfg(windows)]
87 WindowsTimeZoneKeyName => f.write_str(
88 "could not get `TimeZoneKeyName` from \
89 winapi `DYNAMIC_TIME_ZONE_INFORMATION`",
90 ),
91 #[cfg(windows)]
92 WindowsUtf16DecodeInvalid => f.write_str(
93 "failed to convert `u16` slice to UTF-8 \
94 (invalid UTF-16)",
95 ),
96 #[cfg(windows)]
97 WindowsUtf16DecodeNul => f.write_str(
98 "failed to convert `u16` slice to UTF-8 \
99 (no NUL terminator found)",
100 ),
101 }
102 }
103 }
104}