use crate::Month;
use core::num::ParseIntError;
use thiserror::Error;
#[cfg(any(feature = "chrono", feature = "time"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "chrono", feature = "time"))))]
#[derive(Clone, Copy, Debug, Default, Error, Hash, Eq, Ord, PartialEq, PartialOrd)]
#[error("date out of range for foreign date type")]
pub struct TryFromDateError;
#[derive(Clone, Copy, Debug, Default, Error, Hash, Eq, Ord, PartialEq, PartialOrd)]
#[error("invalid month name")]
pub struct ParseMonthError;
#[derive(Clone, Copy, Debug, Default, Error, Hash, Eq, Ord, PartialEq, PartialOrd)]
#[error("value out of range for month number; must be from 1 through 12")]
pub struct TryIntoMonthError;
#[derive(Clone, Copy, Debug, Default, Error, Hash, Eq, Ord, PartialEq, PartialOrd)]
#[error("invalid weekday name")]
pub struct ParseWeekdayError;
#[derive(Clone, Copy, Debug, Default, Error, Hash, Eq, Ord, PartialEq, PartialOrd)]
#[error("value out of range for weekday number; must be from 1 through 7")]
pub struct TryIntoWeekdayError;
#[derive(Copy, Clone, Debug, Eq, Error, Hash, PartialEq)]
pub enum ReformingError {
#[error("reformation date would not cause calendar to advance")]
InvalidReformation,
#[error("arithmetic overflow/underflow")]
Arithmetic,
}
#[derive(Copy, Clone, Debug, Eq, Error, Hash, PartialEq)]
pub enum DateError {
#[error("arithmetic overflow/underflow")]
Arithmetic,
#[error("day {day} is outside of valid range {min_day}-{max_day} for {year:04} {month}")]
DayOutOfRange {
year: i32,
month: Month,
day: u32,
min_day: u32,
max_day: u32,
},
#[error("day-of-year ordinal {ordinal} is outside of valid range 1-{max_ordinal} for year {year:04}")]
OrdinalOutOfRange {
year: i32,
ordinal: u32,
max_ordinal: u32,
},
#[error("date {year:04}-{:02}-{day:02} was skipped by calendar reform", month.number())]
SkippedDate { year: i32, month: Month, day: u32 },
}
#[derive(Clone, Copy, Debug, Default, Error, Hash, Eq, Ord, PartialEq, PartialOrd)]
#[error("arithmetic overflow/underflow")]
pub struct ArithmeticError;
impl From<ArithmeticError> for ReformingError {
fn from(_: ArithmeticError) -> ReformingError {
ReformingError::Arithmetic
}
}
impl From<ArithmeticError> for DateError {
fn from(_: ArithmeticError) -> DateError {
DateError::Arithmetic
}
}
#[derive(Clone, Debug, Eq, Error, PartialEq)]
pub enum ParseDateError {
#[error("invalid calendar date: {0}")]
InvalidDate(#[from] DateError),
#[error("invalid month number: {value}")]
InvalidMonth {
value: u32,
},
#[error("trailing characters after date")]
Trailing,
#[error("expected signed integer, got {got:?}")]
InvalidIntStart {
got: char,
},
#[error("expected unsigned integer, got {got:?}")]
InvalidUIntStart {
got: char,
},
#[error("expected integer, got end of input")]
EmptyInt,
#[error("expected {expected:?}, got {got:?}")]
UnexpectedChar {
expected: char,
got: char,
},
#[error("expected {expected:?}, got end of input")]
UnexpectedEnd {
expected: char,
},
#[error("numeric parse error: {0}")]
ParseInt(#[from] ParseIntError),
}