Skip to main content

timezone_data/
error.rs

1//! Error type for timezone data parsing and lookup.
2
3use core::fmt;
4
5/// Errors produced when loading or parsing timezone data.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7#[non_exhaustive]
8pub enum Error {
9    /// The requested zone was not found in the embedded database.
10    NotFound,
11    /// The TZif binary data is malformed. The payload is a short reason.
12    BadData(&'static str),
13    /// The embedded zip archive could not be read. The payload is a short reason.
14    BadZip(&'static str),
15    /// A POSIX TZ string could not be parsed. The payload is a short reason.
16    BadPosixTz(&'static str),
17}
18
19impl fmt::Display for Error {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        match self {
22            Error::NotFound => f.write_str("timezone not found in embedded data"),
23            Error::BadData(why) => write!(f, "malformed timezone data: {why}"),
24            Error::BadZip(why) => write!(f, "malformed zip archive: {why}"),
25            Error::BadPosixTz(why) => write!(f, "malformed POSIX TZ string: {why}"),
26        }
27    }
28}
29
30impl core::error::Error for Error {}