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 6, 2024
1 parent 19120ac commit e5d78c7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions time/src/serde/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
use core::fmt;
use core::marker::PhantomData;

use std::string::String;

use serde::de;
#[cfg(feature = "parsing")]
use serde::Deserializer;
Expand Down Expand Up @@ -84,7 +86,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 = String::from(value);
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 +286,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 = String::from(value);
if !value.ends_with("Z") {
value.push('Z');
}
OffsetDateTime::parse(&value, &$($ty)+).map_err(E::custom)
}
}

Expand Down

0 comments on commit e5d78c7

Please sign in to comment.