From 9c15ee34668fc99c918656fb2895b6d0bfdf7d75 Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Tue, 9 Apr 2024 21:21:17 -0400 Subject: [PATCH] Permit leap seconds when parsing ISO 8601 --- tests/serde/iso8601.rs | 22 ++++++++++++++++++++++ time/src/parsing/parsable.rs | 2 ++ 2 files changed, 24 insertions(+) diff --git a/tests/serde/iso8601.rs b/tests/serde/iso8601.rs index 471a093ec1..096d09caa7 100644 --- a/tests/serde/iso8601.rs +++ b/tests/serde/iso8601.rs @@ -89,3 +89,25 @@ fn deserialize_error() { "the 'year' component could not be parsed", ); } + +#[test] +fn issue_674_leap_second_support() { + serde_test::assert_de_tokens::( + &Test { + dt: datetime!(2016-12-31 23:59:59.999999999 UTC), + option_dt: Some(datetime!(2016-12-31 23:59:59.999999999 UTC)), + }, + &[ + Token::Struct { + name: "Test", + len: 2, + }, + Token::Str("dt"), + Token::BorrowedStr("2016-12-31T23:59:60.000Z"), + Token::Str("option_dt"), + Token::Some, + Token::BorrowedStr("2016-12-31T23:59:60.000Z"), + Token::StructEnd, + ], + ); +} diff --git a/time/src/parsing/parsable.rs b/time/src/parsing/parsable.rs index 36f663b1f2..1679f63686 100644 --- a/time/src/parsing/parsable.rs +++ b/time/src/parsing/parsable.rs @@ -739,6 +739,8 @@ impl sealed::Sealed for Iso8601 { let mut offset_is_present = false; let mut first_error = None; + parsed.leap_second_allowed = true; + match Self::parse_date(parsed, &mut extended_kind)(input) { Ok(new_input) => { input = new_input;