Skip to content

Commit

Permalink
Parse OffsetDateTimes that don't end in "Z"
Browse files Browse the repository at this point in the history
The `timeStamp` field in the SOTA API omits them.
  • Loading branch information
Goorzhel committed Nov 5, 2024
1 parent 19120ac commit 21da5a2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions time/src/serde/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ impl<'a> de::Visitor<'a> for Visitor<OffsetDateTime> {

#[cfg(feature = "parsing")]
fn visit_str<E: de::Error>(self, value: &str) -> Result<OffsetDateTime, E> {
OffsetDateTime::parse(value, &OFFSET_DATE_TIME_FORMAT).map_err(E::custom)
let mut value = value.to_string();
if !value.ends_with("Z") {
value.push('Z');
}
OffsetDateTime::parse(&value, &OFFSET_DATE_TIME_FORMAT).map_err(E::custom)
}

fn visit_seq<A: de::SeqAccess<'a>>(self, mut seq: A) -> Result<OffsetDateTime, A::Error> {
Expand Down Expand Up @@ -280,7 +284,11 @@ macro_rules! well_known {
}

fn visit_str<E: de::Error>(self, value: &str) -> Result<OffsetDateTime, E> {
OffsetDateTime::parse(value, &$($ty)+).map_err(E::custom)
let mut value = value.to_string();
if !value.ends_with("Z") {
value.push('Z');
}
OffsetDateTime::parse(&value, &$($ty)+).map_err(E::custom)
}
}

Expand Down

0 comments on commit 21da5a2

Please sign in to comment.