dates_str/
errors.rs

1use std::fmt::Display;
2
3#[derive(Debug)]
4/// Errors on date boundaries
5///
6/// The errors given when a date is out of bounds, for example a 13th month or the 41st day of a
7/// month.
8pub enum DateErrors {
9    /// Enum variant when day is out of bounds
10    InvalidDay {
11        /// They "day" that provoked the error.
12        day: u8,
13    },
14    /// Enum variant when month is out of bounds
15    InvalidMonth {
16        /// The "month" that provoked the error
17        month: u8,
18    },
19    /// Enum variant when a formatter field is not resolved
20    FormatDateError,
21    /// Invalid year variant.
22    InvalidYear(u64),
23
24    /// Error to return when triying to parse something that cannot be respresented as a number
25    InvalidParsing(String),
26}
27
28impl Display for DateErrors {
29    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30        match self {
31            Self::InvalidDay { day } => write!(f, "Invalid Day: provided {}", day),
32            Self::InvalidMonth { month } => write!(f, "Invalid Month: provided {}", month),
33            Self::FormatDateError => write!(f, "Format not recognized"),
34            Self::InvalidYear(year) => write!(f, "Invalif year provided: {}", year),
35            Self::InvalidParsing(s) => write!(f, "Cannot parse {}: not a number...", s),
36        }
37    }
38}
39
40impl std::error::Error for DateErrors {}