#[derive(Debug, Clone, PartialEq)]
pub struct DateTime(chrono::DateTime<chrono::FixedOffset>);
impl std::fmt::Display for DateTime {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.to_rfc3339().fmt(f)
}
}
impl std::str::FromStr for DateTime {
type Err = chrono::format::ParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let tz_provided = s.ends_with('Z') || s.contains('+') || s.matches('-').count() == 3;
let s_with_timezone = if tz_provided {
s.to_string()
} else {
format!("{s}Z")
};
match chrono::DateTime::parse_from_rfc3339(&s_with_timezone) {
Ok(cdt) => Ok(DateTime(cdt)),
Err(err) => Err(err),
}
}
}