chinese_format/gregorian/date/
errors.rs1use std::{error::Error, fmt::Display};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
14pub struct MonthOutOfRange(pub u8);
15
16impl Display for MonthOutOfRange {
17 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18 write!(f, "Month out of range: {}", self.0)
19 }
20}
21
22impl Error for MonthOutOfRange {}
23
24#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
35pub struct DayOutOfRange(pub u8);
36
37impl Display for DayOutOfRange {
38 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39 write!(f, "Day out of range: {}", self.0)
40 }
41}
42
43impl Error for DayOutOfRange {}
44
45#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
56pub struct WeekDayOutOfRange(pub u8);
57
58impl Display for WeekDayOutOfRange {
59 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
60 write!(f, "Week day out of range: {}", self.0)
61 }
62}
63
64impl Error for WeekDayOutOfRange {}
65
66#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
90pub struct InvalidDate {
91 pub year: Option<u16>,
92 pub month: u8,
93 pub day: u8,
94}
95
96impl Display for InvalidDate {
97 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
98 match self.year {
99 Some(year) => write!(f, "Invalid date: {}-{}-{}", year, self.month, self.day),
100
101 None => write!(f, "Invalid date: {}-{}", self.month, self.day),
102 }
103 }
104}
105
106impl Error for InvalidDate {}