1use crate::error;
2
3#[derive(Clone, Debug)]
4pub(crate) enum Error {
5 FailedAddDays,
6 FailedAddDurationOverflowing,
7 FailedAddSpanDate,
8 FailedAddSpanOverflowing,
9 FailedAddSpanTime,
10 IllegalTimeWithMicrosecond,
11 IllegalTimeWithMillisecond,
12 IllegalTimeWithNanosecond,
13 OverflowDaysDuration,
14 OverflowTimeNanoseconds,
15}
16
17impl From<Error> for error::Error {
18 #[cold]
19 #[inline(never)]
20 fn from(err: Error) -> error::Error {
21 error::ErrorKind::Civil(err).into()
22 }
23}
24
25impl error::IntoError for Error {
26 fn into_error(self) -> error::Error {
27 self.into()
28 }
29}
30
31impl core::fmt::Display for Error {
32 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
33 use self::Error::*;
34
35 match *self {
36 FailedAddDays => f.write_str("failed to add days to date"),
37 FailedAddDurationOverflowing => {
38 f.write_str("failed to add overflowing duration")
39 }
40 FailedAddSpanDate => f.write_str("failed to add span to date"),
41 FailedAddSpanOverflowing => {
42 f.write_str("failed to add overflowing span")
43 }
44 FailedAddSpanTime => f.write_str("failed to add span to time"),
45 IllegalTimeWithMicrosecond => f.write_str(
46 "cannot set both `TimeWith::microsecond` \
47 and `TimeWith::subsec_nanosecond`",
48 ),
49 IllegalTimeWithMillisecond => f.write_str(
50 "cannot set both `TimeWith::millisecond` \
51 and `TimeWith::subsec_nanosecond`",
52 ),
53 IllegalTimeWithNanosecond => f.write_str(
54 "cannot set both `TimeWith::nanosecond` \
55 and `TimeWith::subsec_nanosecond`",
56 ),
57 OverflowDaysDuration => f.write_str(
58 "number of days derived from duration exceed's \
59 Jiff's datetime limits",
60 ),
61 OverflowTimeNanoseconds => {
62 f.write_str("adding duration to time overflowed")
63 }
64 }
65 }
66}