From 8ebbb736dfcc207c99e16a76493f07e6291bf35c Mon Sep 17 00:00:00 2001 From: Paul Dicker Date: Sat, 10 Jun 2023 16:53:37 +0200 Subject: [PATCH] Make parsing `%:z` conform to documentation --- src/format/mod.rs | 1 - src/format/parse.rs | 18 +++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/format/mod.rs b/src/format/mod.rs index 2071de6387..12f316a3e4 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -209,7 +209,6 @@ pub enum Fixed { TimezoneName, /// Offset from the local time to UTC (`+09:00` or `-04:00` or `+00:00`). /// - /// In the parser, the colon can be omitted and/or surrounded with any amount of whitespace. /// The offset is limited from `-24:00` to `+24:00`, /// which is the same as [`FixedOffset`](../offset/struct.FixedOffset.html)'s range. TimezoneOffsetColon, diff --git a/src/format/parse.rs b/src/format/parse.rs index 9cbcca78c3..69cb9a27df 100644 --- a/src/format/parse.rs +++ b/src/format/parse.rs @@ -460,14 +460,22 @@ where try_consume!(scan::timezone_name_skip(s)); } - &TimezoneOffsetColon - | &TimezoneOffset - | &TimezoneOffsetColonZ - | &TimezoneOffsetZ => { + &TimezoneOffset | &TimezoneOffsetZ => { let offset_format = UtcOffsetFormat { precision: OffsetPrecision::Minutes, colons: Colon::Maybe, - allow_zulu: spec == &TimezoneOffsetColonZ || spec == &TimezoneOffsetZ, + allow_zulu: spec == &TimezoneOffsetZ, + padding: Pad::Zero, + }; + let offset = try_consume!(scan::utc_offset(s.trim_start(), offset_format)); + parsed.set_offset(i64::from(offset)).map_err(|e| (s, e))?; + } + + &TimezoneOffsetColon | &TimezoneOffsetColonZ => { + let offset_format = UtcOffsetFormat { + precision: OffsetPrecision::Minutes, + colons: Colon::Colon, + allow_zulu: spec == &TimezoneOffsetColonZ, padding: Pad::Zero, }; let offset = try_consume!(scan::utc_offset(s.trim_start(), offset_format));