From 9226811e263054171c40f47be5db91af670b3c24 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 11 Feb 2025 00:44:14 +0100 Subject: [PATCH] hooktypes: restore support for parsing local times The `%z` parsing actually was used in production, but it doesn't just parse *names*, but also *numerical* offsets. Restore the code and add a test. --- CHANGELOG.md | 7 +++++++ src/hooktypes.rs | 10 +++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f65bed21..b6f52e64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# v0.1708.2 (unreleased) + +## Fixes + + * `hooktypes::HookDate` parsing of local-offset time specifications has been + restored. + # v0.1708.1 ## Breaking changes diff --git a/src/hooktypes.rs b/src/hooktypes.rs index 57142e0e..f44b0813 100644 --- a/src/hooktypes.rs +++ b/src/hooktypes.rs @@ -197,15 +197,10 @@ impl<'de> Deserialize<'de> for HookDate { // XXX(chrono-0.4.25): `dt.and_utc()` .map(|dt| Utc.from_utc_datetime(&dt)) .or_else(|_| DateTime::parse_from_rfc3339(&val).map(|dt| dt.with_timezone(&Utc))) - /* - * `chrono` doesn't actually parse time zone *names* as they are very ambiguous. Since - * this never worked, comment it out, but leave it here for posterity. .or_else(|_| { - // test_hookdate_parse("2024-05-06 10:34:38 EDT"); DateTime::parse_from_str(&val, "%Y-%m-%d %H:%M:%S %z") .map(|dt| dt.with_timezone(&Utc)) }) - */ .map_err(|err| { D::Error::invalid_value( Unexpected::Other("hook date"), @@ -274,6 +269,11 @@ mod tests { test_hookdate_parse("2024-05-06 10:34:38 UTC"); } + #[test] + fn test_hookdate_literal_local() { + test_hookdate_parse("2024-05-06 05:34:38 -0500"); + } + #[test] fn test_hookdate_rfc3339() { test_hookdate_parse("2024-05-06T10:34:38Z"); -- GitLab