1use crate::{error, Unit};
2
3#[derive(Clone, Debug)]
4pub(crate) enum Error {
5 AddDateTime,
6 AddDays,
7 AddTimestamp,
8 ConvertDateTimeToTimestamp,
9 ConvertIntermediateDatetime,
10 FailedLengthOfDay,
11 FailedSpanNanoseconds,
12 FailedStartOfDay,
13 MismatchTimeZoneUntil { largest: Unit },
14}
15
16impl From<Error> for error::Error {
17 #[cold]
18 #[inline(never)]
19 fn from(err: Error) -> error::Error {
20 error::ErrorKind::Zoned(err).into()
21 }
22}
23
24impl error::IntoError for Error {
25 fn into_error(self) -> error::Error {
26 self.into()
27 }
28}
29
30impl core::fmt::Display for Error {
31 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
32 use self::Error::*;
33
34 match *self {
35 AddDateTime => f.write_str(
36 "failed to add span to datetime from zoned datetime",
37 ),
38 AddDays => {
39 f.write_str("failed to add days to date in zoned datetime")
40 }
41 AddTimestamp => f.write_str(
42 "failed to add span to timestamp from zoned datetime",
43 ),
44 ConvertDateTimeToTimestamp => {
45 f.write_str("failed to convert civil datetime to timestamp")
46 }
47 ConvertIntermediateDatetime => f.write_str(
48 "failed to convert intermediate datetime \
49 to zoned timestamp",
50 ),
51 FailedLengthOfDay => f.write_str(
52 "failed to add 1 day to zoned datetime to find length of day",
53 ),
54 FailedSpanNanoseconds => f.write_str(
55 "failed to compute span in nanoseconds \
56 between zoned datetimes",
57 ),
58 FailedStartOfDay => {
59 f.write_str("failed to find start of day for zoned datetime")
60 }
61 MismatchTimeZoneUntil { largest } => write!(
62 f,
63 "computing the span between zoned datetimes, with \
64 {largest} units, requires that the time zones are \
65 equivalent, but the zoned datetimes have distinct \
66 time zones",
67 largest = largest.singular(),
68 ),
69 }
70 }
71}