Debian Codegraph @

debian/missing-sources/jiff-static/src/shared/error/itime.rs

raw
1 // auto-generated by: jiff-cli generate shared
2
3 use crate::shared::{
4 error,
5 util::itime::{days_in_month, days_in_year, IEpochDay},
6 };
7
8 // N.B. Every variant in this error type is a range error.
9 #[derive(Clone, Debug, Eq, PartialEq)]
10 pub(crate) enum Error {
11 DateInvalidDayOfYear { year: i16 },
12 DateInvalidDayOfYearNoLeap,
13 DateInvalidDays { year: i16, month: i8 },
14 DateTimeSeconds,
15 // TODO: I believe this can never happen.
16 DayOfYear,
17 EpochDayDays,
18 EpochDayI32,
19 NthWeekdayOfMonth,
20 Tomorrow,
21 YearNext,
22 YearPrevious,
23 Yesterday,
24 }
25
26 impl From<Error> for error::Error {
27 #[cold]
28 #[inline(never)]
29 fn from(err: Error) -> error::Error {
30 error::ErrorKind::Time(err).into()
31 }
32 }
33
34 // impl error::IntoError for Error {
35 // fn into_error(self) -> error::Error {
36 // self.into()
37 // }
38 // }
39
40 impl core::fmt::Display for Error {
41 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
42 use self::Error::*;
43
44 match *self {
45 DateInvalidDayOfYear { year } => write!(
46 f,
47 "number of days for `{year:04}` is invalid, \
48 must be in range `1..={max_day}`",
49 max_day = days_in_year(year),
50 ),
51 DateInvalidDayOfYearNoLeap => f.write_str(
52 "number of days is invalid, must be in range `1..=365`",
53 ),
54 DateInvalidDays { year, month } => write!(
55 f,
56 "number of days for `{year:04}-{month:02}` is invalid, \
57 must be in range `1..={max_day}`",
58 max_day = days_in_month(year, month),
59 ),
60 DateTimeSeconds => {
61 f.write_str("adding seconds to datetime overflowed")
62 }
63 DayOfYear => f.write_str("day of year is invalid"),
64 EpochDayDays => write!(
65 f,
66 "adding to epoch day resulted in a value outside \
67 the allowed range of `{min}..={max}`",
68 min = IEpochDay::MIN.epoch_day,
69 max = IEpochDay::MAX.epoch_day,
70 ),
71 EpochDayI32 => f.write_str(
72 "adding to epoch day overflowed 32-bit signed integer",
73 ),
74 NthWeekdayOfMonth => f.write_str(
75 "invalid nth weekday of month, \
76 must be non-zero and in range `-5..=5`",
77 ),
78 Tomorrow => f.write_str(
79 "returning tomorrow for `9999-12-31` is not \
80 possible because it is greater than Jiff's supported
81 maximum date",
82 ),
83 YearNext => f.write_str(
84 "creating a date for a year following `9999` is \
85 not possible because it is greater than Jiff's supported \
86 maximum date",
87 ),
88 YearPrevious => f.write_str(
89 "creating a date for a year preceding `-9999` is \
90 not possible because it is less than Jiff's supported \
91 minimum date",
92 ),
93 Yesterday => f.write_str(
94 "returning yesterday for `-9999-01-01` is not \
95 possible because it is less than Jiff's supported
96 minimum date",
97 ),
98 }
99 }
100 }