Skip to main content

satellite_datetime/
error.rs

1//! Errors that never panic on library paths.
2
3use core::fmt;
4
5/// Recoverable failure from a conversion, parse, or arithmetic operation.
6#[derive(Clone, Copy, Debug, Eq, PartialEq)]
7pub enum Error {
8    /// `i128` nanosecond arithmetic overflowed.
9    Overflow,
10    /// Year, month, or day is not a valid Gregorian calendar date.
11    InvalidDate,
12    /// Hour, minute, second, or nanosecond is out of range (UTC leap: second may be 60).
13    InvalidTime,
14    /// The instant is before UTC was defined (1960-01-01).
15    UtcUndefined,
16    /// Leap-second table does not cover this future UTC date with certainty.
17    LeapTableExpired,
18    /// UT1/DUT1 is not defined before the modern UTC era (1972-01-01).
19    Ut1Undefined,
20    /// DUT1 table does not cover this UTC date.
21    Ut1TableExpired,
22    /// ISO 8601 / RFC 3339 text could not be parsed.
23    Parse,
24    /// Buffer was too small to hold the formatted timestamp.
25    BufferTooSmall,
26    /// CCSDS field length or payload is illegal.
27    Codec,
28    /// Local civil time falls in a DST spring-forward gap.
29    DstGap,
30    /// Requested feature data (zone, body) is not in this build.
31    Unsupported,
32}
33
34impl fmt::Display for Error {
35    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36        match self {
37            Self::Overflow => f.write_str("nanosecond arithmetic overflow"),
38            Self::InvalidDate => f.write_str("invalid calendar date"),
39            Self::InvalidTime => f.write_str("invalid clock time"),
40            Self::UtcUndefined => f.write_str("UTC is not defined before 1960-01-01"),
41            Self::LeapTableExpired => {
42                f.write_str("UTC date is beyond the pinned leap-second table")
43            }
44            Self::Ut1Undefined => f.write_str("UT1 is not defined before 1972-01-01 in this crate"),
45            Self::Ut1TableExpired => f.write_str("UTC date is beyond the pinned DUT1 table"),
46            Self::Parse => f.write_str("timestamp parse error"),
47            Self::BufferTooSmall => f.write_str("output buffer too small"),
48            Self::Codec => f.write_str("time-code codec error"),
49            Self::DstGap => f.write_str("civil time does not exist (DST gap)"),
50            Self::Unsupported => f.write_str("unsupported in this crate feature set"),
51        }
52    }
53}
54
55#[cfg(feature = "std")]
56impl std::error::Error for Error {}
57
58/// Crate-wide result type.
59pub type Result<T> = core::result::Result<T, Error>;