| 1 |
use crate::{ |
| 2 |
error, |
| 3 |
tz::{Offset, TimeZone}, |
| 4 |
}; |
| 5 |
|
| 6 |
#[derive(Clone, Debug)] |
| 7 |
#[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 8 |
pub(crate) enum Error { |
| 9 |
BecauseFold { before: Offset, after: Offset }, |
| 10 |
BecauseGap { before: Offset, after: Offset }, |
| 11 |
InTimeZone { tz: TimeZone }, |
| 12 |
} |
| 13 |
|
| 14 |
impl From<Error> for error::Error { |
| 15 |
#[cold] |
| 16 |
#[inline(never)] |
| 17 |
fn from(err: Error) -> error::Error { |
| 18 |
error::ErrorKind::TzAmbiguous(err).into() |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
impl error::IntoError for Error { |
| 23 |
fn into_error(self) -> error::Error { |
| 24 |
self.into() |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
impl core::fmt::Display for Error { |
| 29 |
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { |
| 30 |
use self::Error::*; |
| 31 |
|
| 32 |
match *self { |
| 33 |
BecauseFold { before, after } => write!( |
| 34 |
f, |
| 35 |
"datetime is ambiguous since it falls into a \ |
| 36 |
fold between offsets {before} and {after}", |
| 37 |
), |
| 38 |
BecauseGap { before, after } => write!( |
| 39 |
f, |
| 40 |
"datetime is ambiguous since it falls into a \ |
| 41 |
gap between offsets {before} and {after}", |
| 42 |
), |
| 43 |
InTimeZone { ref tz } => write!( |
| 44 |
f, |
| 45 |
"error converting datetime to instant in time zone {tz}", |
| 46 |
tz = tz.diagnostic_name(), |
| 47 |
), |
| 48 |
} |
| 49 |
} |
| 50 |
} |