use core::fmt;
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct OutOfRangeError(pub(crate) ());
impl fmt::Display for OutOfRangeError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
"timestamp out of representable range".fmt(fmt)
}
}
#[cfg(feature = "std")]
impl std::error::Error for OutOfRangeError {}
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum DateTimeError {
InvalidMonth(u8),
InvalidDayOfMonth(u8),
InvalidHour(u8),
InvalidMinute(u8),
InvalidSecond(u8),
InvalidNanosecond(u32),
OutOfRange,
}
impl fmt::Display for DateTimeError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidMonth(month) => write!(fmt, "month numeral '{}' is not valid", month),
Self::InvalidDayOfMonth(day) => {
write!(fmt, "day of month '{}' is not valid for this date", day)
}
Self::InvalidHour(hour) => write!(fmt, "hour numeral '{}' is not valid", hour),
Self::InvalidMinute(min) => write!(fmt, "minute numeral '{}' is not valid", min),
Self::InvalidSecond(sec) => write!(fmt, "second numeral '{}' is not valid", sec),
Self::InvalidNanosecond(nanosec) => {
write!(fmt, "nanosecond value '{}' is not valid", nanosec)
}
Self::OutOfRange => "timestamp out of representable range".fmt(fmt),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for DateTimeError {}
#[derive(Debug, PartialEq, Eq, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ParseDateTimeError {
InvalidFieldValue,
InvalidFieldWidth,
MissingField,
RangeError(DateTimeError),
}
impl fmt::Display for ParseDateTimeError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidFieldValue => "one of the fields is invalid".fmt(fmt),
Self::InvalidFieldWidth => "the width of one of the fields is invalid".fmt(fmt),
Self::MissingField => "a fields is missing".fmt(fmt),
Self::RangeError(err) => err.fmt(fmt),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for ParseDateTimeError {}