Skip to content

Commit

Permalink
Parse invalid single-letter timezones as -00:00
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Feb 28, 2024
1 parent 431adde commit cc18784
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/format/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1645,8 +1645,9 @@ mod tests {
("Tue, 20 Jan 2015 17:35:20 PDT", Ok(ymd_hmsn(2015, 1, 20, 17, 35, 20, 0, -7))),
("Tue, 20 Jan 2015 17:35:20 PST", Ok(ymd_hmsn(2015, 1, 20, 17, 35, 20, 0, -8))),
("Tue, 20 Jan 2015 17:35:20 pst", Ok(ymd_hmsn(2015, 1, 20, 17, 35, 20, 0, -8))),
// named single-letter military timezones must fallback to +0000
// Z is the only single-letter military timezones that maps to +0000
("Tue, 20 Jan 2015 17:35:20 Z", Ok(ymd_hmsn(2015, 1, 20, 17, 35, 20, 0, 0))),
// named single-letter military timezones must fallback to -0000
("Tue, 20 Jan 2015 17:35:20 A", Ok(ymd_hmsn(2015, 1, 20, 17, 35, 20, 0, 0))),
("Tue, 20 Jan 2015 17:35:20 a", Ok(ymd_hmsn(2015, 1, 20, 17, 35, 20, 0, 0))),
("Tue, 20 Jan 2015 17:35:20 K", Ok(ymd_hmsn(2015, 1, 20, 17, 35, 20, 0, 0))),
Expand Down Expand Up @@ -1684,6 +1685,22 @@ mod tests {
}
}

#[test]
fn test_rfc2822_no_offset_info() {
fn rfc2822_to_offset(date: &str) -> FixedOffset {
let mut parsed = Parsed::new();
parse(&mut parsed, date, [Item::Fixed(Fixed::RFC2822)].iter()).unwrap();
parsed.to_fixed_offset().unwrap()
}
assert_eq!(
rfc2822_to_offset("Tue, 20 Jan 2015 17:35:20 -0000"),
FixedOffset::OFFSET_UNKNOWN
);
assert_eq!(rfc2822_to_offset("Tue, 20 Jan 2015 17:35:20 A"), FixedOffset::OFFSET_UNKNOWN);
assert_eq!(rfc2822_to_offset("Tue, 20 Jan 2015 17:35:20 a"), FixedOffset::OFFSET_UNKNOWN);
assert_eq!(rfc2822_to_offset("Tue, 20 Jan 2015 17:35:20 K"), FixedOffset::OFFSET_UNKNOWN);
}

#[test]
fn parse_rfc850() {
static RFC850_FMT: &str = "%A, %d-%b-%y %T GMT";
Expand Down

0 comments on commit cc18784

Please sign in to comment.