1use core::fmt;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum TimeError {
8 InvalidDate { year: i32, month: u8, day: u8 },
10 InvalidTime { hour: u8, minute: u8 },
12 InvalidSecond,
14 InvalidFormat,
16 KernelDateUnsupported,
21 EopMissing,
23 EopParse,
25 SclkParse,
27 SclkMissing(&'static str),
29 SclkUnsupported,
31 SclkPartitionsUnsupported,
33 Ut1OutOfRange,
35 InvalidLeapSecond,
39 UtcOutOfRange,
41 LskParse,
43 LskMissing(&'static str),
45 Overflow,
47}
48
49impl fmt::Display for TimeError {
50 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51 match self {
52 TimeError::InvalidDate { year, month, day } => {
53 write!(f, "invalid calendar date {year:04}-{month:02}-{day:02}")
54 }
55 TimeError::InvalidTime { hour, minute } => {
56 write!(f, "invalid time of day {hour:02}:{minute:02}")
57 }
58 TimeError::InvalidSecond => write!(f, "invalid seconds component"),
59 TimeError::InvalidFormat => write!(f, "unsupported formatting token"),
60 TimeError::KernelDateUnsupported => {
61 write!(f, "unsupported kernel date literal")
62 }
63 TimeError::EopMissing => write!(f, "EOP table is empty"),
64 TimeError::EopParse => write!(f, "could not parse the IERS EOP file"),
65 TimeError::SclkParse => write!(f, "could not parse the spacecraft clock kernel"),
66 TimeError::SclkMissing(name) => {
67 write!(f, "spacecraft clock kernel is missing {name}")
68 }
69 TimeError::SclkUnsupported => {
70 write!(
71 f,
72 "unsupported spacecraft clock type (only type 1 is supported)"
73 )
74 }
75 TimeError::SclkPartitionsUnsupported => {
76 write!(
77 f,
78 "SCLK partition-aware field/string conversion is not implemented"
79 )
80 }
81 TimeError::Ut1OutOfRange => {
82 write!(f, "requested epoch lies outside the EOP table")
83 }
84 TimeError::InvalidLeapSecond => {
85 write!(f, "UTC time does not exist at this leap-second boundary")
86 }
87 TimeError::UtcOutOfRange => {
88 write!(f, "UTC epoch lies outside the supplied leap-second table")
89 }
90 TimeError::LskParse => write!(f, "could not parse the leap-second kernel"),
91 TimeError::LskMissing(name) => write!(f, "leap-second kernel is missing {name}"),
92 TimeError::Overflow => write!(f, "time arithmetic overflow"),
93 }
94 }
95}
96
97#[cfg(feature = "std")]
98impl std::error::Error for TimeError {}