1use std::fmt::Display;
2
3use crate::{BadiMonth, LAST_YEAR_SUPPORTED};
4
5#[derive(Debug)]
7pub enum BadiDateError {
8 DayInvalid(BadiMonth, u16, u16),
10 MonthInvalid(BadiMonth),
12 DateNotSupported,
14}
15
16impl BadiDateError {
17 pub fn message(&self) -> String {
19 match self {
20 BadiDateError::DayInvalid(month, day, max_day) => {
21 format!(
22 "ERROR: Invalid Badi month: day {} is not in the range [1-{}] for {}",
23 day,
24 max_day,
25 month.description()
26 )
27 }
28 BadiDateError::MonthInvalid(month) => match month {
29 BadiMonth::Month(month) => {
30 format!(
31 "ERROR: BadiMonth::Month({}) is not in the range [1-19]",
32 month
33 )
34 }
35 BadiMonth::AyyamIHa => String::new(),
36 },
37 BadiDateError::DateNotSupported => {
38 format!(
39 "The given date is not supported; year must be in the range [1-{}]",
40 LAST_YEAR_SUPPORTED
41 )
42 }
43 }
44 }
45}
46
47impl Display for BadiDateError {
48 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49 write!(f, "BadiDateError: {}", self.message())
50 }
51}