Skip to content

Commit

Permalink
Make parsing %:::z conform to documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Jul 1, 2023
1 parent 2ec53e8 commit 05fe9cf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ pub enum Fixed {
TimezoneOffsetDoubleColon,
/// Offset from the local time to UTC without minutes (`+09` or `-04` or `+00`).
///
/// In the parser, the colon can be omitted and/or surrounded with any amount of whitespace.
/// The offset is limited from `-24` to `+24`,
/// which is the same as [`FixedOffset`](../offset/struct.FixedOffset.html)'s range.
TimezoneOffsetTripleColon,
Expand Down
16 changes: 11 additions & 5 deletions src/format/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,6 @@ where

&TimezoneOffsetColon
| &TimezoneOffsetDoubleColon
| &TimezoneOffsetTripleColon
| &TimezoneOffset
| &TimezoneOffsetColonZ
| &TimezoneOffsetZ => {
Expand All @@ -541,6 +540,17 @@ where
parsed.set_offset(i64::from(offset)).map_err(|e| (s, e))?;
}

&TimezoneOffsetTripleColon => {
let offset_format = OffsetFormat {
precision: OffsetPrecision::Hours,
colons: Colons::None,
allow_zulu: false,
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))?;
}

&Internal(InternalFixed {
val: InternalInternal::TimezoneOffsetPermissive,
}) => {
Expand Down Expand Up @@ -1051,10 +1061,6 @@ mod tests {
check!(" :Z", [fixed(Fixed::TimezoneOffsetColon)]; INVALID);
check!(" Z", [fixed(Fixed::TimezoneOffsetColon)]; INVALID);
check!(" z", [fixed(Fixed::TimezoneOffsetColon)]; INVALID);
// testing `TimezoneOffsetColon` also tests same path as `TimezoneOffsetDoubleColon`
// and `TimezoneOffsetTripleColon` for function `parse_internal`.
// No need for separate tests for `TimezoneOffsetDoubleColon` and
// `TimezoneOffsetTripleColon`.

// TimezoneOffsetZ
check!("1", [fixed(Fixed::TimezoneOffsetZ)]; INVALID);
Expand Down

0 comments on commit 05fe9cf

Please sign in to comment.