use alloc::string::String;
use core::str::FromStr;
use crate::parsers;
#[allow(missing_docs)]
#[derive(Eq, PartialEq, Debug, Copy, Clone)]
pub enum Date {
YMD { year: i32, month: u32, day: u32 },
Week { year: i32, ww: u32, d: u32 },
Ordinal { year: i32, ddd: u32 },
}
impl Default for Date {
fn default() -> Date {
Date::YMD {
year: 0,
month: 0,
day: 0,
}
}
}
impl FromStr for Date {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
date(s)
}
}
pub fn date(string: &str) -> Result<Date, String> {
if let Ok((_, parsed)) = parsers::parse_date(string.as_bytes()) {
Ok(parsed)
} else {
Err(format!("Failed to parse date: {}", string))
}
}