1#[derive(Debug, Clone, PartialEq)]
5pub struct DateTime(chrono::DateTime<chrono::FixedOffset>);
6
7impl std::fmt::Display for DateTime {
8 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
9 self.0.to_rfc3339().fmt(f)
10 }
11}
12
13impl std::str::FromStr for DateTime {
14 type Err = chrono::format::ParseError;
15
16 fn from_str(s: &str) -> Result<Self, Self::Err> {
22 let tz_provided = s.ends_with('Z') || s.contains('+') || s.matches('-').count() == 3;
23 let s_with_timezone = if tz_provided {
24 s.to_string()
25 } else {
26 format!("{s}Z")
27 };
28 match chrono::DateTime::parse_from_rfc3339(&s_with_timezone) {
29 Ok(cdt) => Ok(DateTime(cdt)),
30 Err(err) => Err(err),
31 }
32 }
33}