use std::fmt::Display;
use crate::{BadiMonth, LAST_YEAR_SUPPORTED};
#[derive(Debug)]
pub enum BadiDateError {
DayInvalid(BadiMonth, u16, u16),
MonthInvalid(BadiMonth),
DateNotSupported,
}
impl BadiDateError {
pub fn message(&self) -> String {
match self {
BadiDateError::DayInvalid(month, day, max_day) => {
format!(
"ERROR: Invalid Badi month: day {} is not in the range [1-{}] for {}",
day,
max_day,
month.description()
)
}
BadiDateError::MonthInvalid(month) => match month {
BadiMonth::Month(month) => {
format!(
"ERROR: BadiMonth::Month({}) is not in the range [1-19]",
month
)
}
BadiMonth::AyyamIHa => String::new(),
},
BadiDateError::DateNotSupported => {
format!(
"The given date is not supported; year must be in the range [1-{}]",
LAST_YEAR_SUPPORTED
)
}
}
}
}
impl Display for BadiDateError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "BadiDateError: {}", self.message())
}
}