Skip to content

Commit bfa3332

Browse files
committed
RFC 2822 single-letter obsolete tests
Add follow-up tests to PR chronotope#1013 Link to RFC 2822 section.
1 parent 5ecf30b commit bfa3332

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/format/parse.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -854,9 +854,11 @@ fn test_rfc2822() {
854854
("Tue, 20 Jan 2015 17:35:20 -0890", Err(OUT_OF_RANGE)), // bad offset
855855
("6 Jun 1944 04:00:00Z", Err(INVALID)), // bad offset (zulu not allowed)
856856
("Tue, 20 Jan 2015 17:35:20 HAS", Err(NOT_ENOUGH)), // bad named time zone
857-
// named timezones
857+
// named timezones that have specific timezone offsets
858+
// see https://www.rfc-editor.org/rfc/rfc2822#section-4.3
858859
("Tue, 20 Jan 2015 17:35:20 GMT", Ok("Tue, 20 Jan 2015 17:35:20 +0000")),
859860
("Tue, 20 Jan 2015 17:35:20 UT", Ok("Tue, 20 Jan 2015 17:35:20 +0000")),
861+
("Tue, 20 Jan 2015 17:35:20 ut", Ok("Tue, 20 Jan 2015 17:35:20 +0000")),
860862
("Tue, 20 Jan 2015 17:35:20 EDT", Ok("Tue, 20 Jan 2015 17:35:20 -0400")),
861863
("Tue, 20 Jan 2015 17:35:20 EST", Ok("Tue, 20 Jan 2015 17:35:20 -0500")),
862864
("Tue, 20 Jan 2015 17:35:20 CDT", Ok("Tue, 20 Jan 2015 17:35:20 -0500")),
@@ -865,9 +867,15 @@ fn test_rfc2822() {
865867
("Tue, 20 Jan 2015 17:35:20 MST", Ok("Tue, 20 Jan 2015 17:35:20 -0700")),
866868
("Tue, 20 Jan 2015 17:35:20 PDT", Ok("Tue, 20 Jan 2015 17:35:20 -0700")),
867869
("Tue, 20 Jan 2015 17:35:20 PST", Ok("Tue, 20 Jan 2015 17:35:20 -0800")),
870+
("Tue, 20 Jan 2015 17:35:20 pst", Ok("Tue, 20 Jan 2015 17:35:20 -0800")),
871+
// named single-letter military timezones must fallback to +0000
868872
("Tue, 20 Jan 2015 17:35:20 Z", Ok("Tue, 20 Jan 2015 17:35:20 +0000")),
869873
("Tue, 20 Jan 2015 17:35:20 A", Ok("Tue, 20 Jan 2015 17:35:20 +0000")),
874+
("Tue, 20 Jan 2015 17:35:20 a", Ok("Tue, 20 Jan 2015 17:35:20 +0000")),
870875
("Tue, 20 Jan 2015 17:35:20 K", Ok("Tue, 20 Jan 2015 17:35:20 +0000")),
876+
("Tue, 20 Jan 2015 17:35:20 k", Ok("Tue, 20 Jan 2015 17:35:20 +0000")),
877+
// named single-letter timezone "J" is specifically not valid
878+
("Tue, 20 Jan 2015 17:35:20 J", Err(NOT_ENOUGH)),
871879
];
872880

873881
fn rfc2822_to_datetime(date: &str) -> ParseResult<DateTime<FixedOffset>> {

src/format/scan.rs

+3
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ where
308308

309309
/// Same as `timezone_offset` but also allows for RFC 2822 legacy timezones.
310310
/// May return `None` which indicates an insufficient offset data (i.e. `-0000`).
311+
/// See [RFC 2822 Section 4.3].
312+
///
313+
/// [RFC 2822 Section 4.3]: https://tools.ietf.org/html/rfc2822#section-4.3
311314
pub(super) fn timezone_offset_2822(s: &str) -> ParseResult<(&str, Option<i32>)> {
312315
// tries to parse legacy time zone names
313316
let upto = s

0 commit comments

Comments
 (0)