From 260342a59228c0f2cbdb4eec5ebbb513d9516d50 Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Mon, 28 Mar 2016 09:43:52 -0700 Subject: [PATCH 1/3] Add regression test for RFC850 parsing Although not supported directly by chrono, users should be able to specify the RFC850 format and expect it to parse properly. RFC850 is important since HTTP/1.1 specifies HTTP-date = rfc1123-date | rfc850-date | asctime-date --- src/format/parse.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/format/parse.rs b/src/format/parse.rs index 6896d65..316cfac 100644 --- a/src/format/parse.rs +++ b/src/format/parse.rs @@ -635,6 +635,25 @@ fn test_rfc2822() { }; } + + +#[cfg(test)] +#[test] +fn parse_rfc850() { + use ::{UTC, TimeZone}; + + static RFC850_FMT: &'static str = "%A, %d-%b-%y %T GMT"; + + let dt_str = "Sunday, 06-Nov-94 08:49:37 GMT"; + let dt = UTC.ymd(1994, 11, 6).and_hms(8, 49, 37); + + // Check that the format is what we expect + assert_eq!(dt.format(RFC850_FMT).to_string(), dt_str); + + // Check that it parses correctly + assert_eq!(Ok(dt), UTC.datetime_from_str("Sunday, 06-Nov-94 08:49:37 GMT", RFC850_FMT)); +} + #[cfg(test)] #[test] fn test_rfc3339() { From 33516cc9f1ad1c78c214ca83c07d6c93785efb6c Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Mon, 28 Mar 2016 09:46:25 -0700 Subject: [PATCH 2/3] Fix parsing LongWeekday for Sunday Only `Sun` was consumed, and the string being parsed would have `day` left over at the front. --- src/format/scan.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/format/scan.rs b/src/format/scan.rs index 0676fc1..b456cca 100644 --- a/src/format/scan.rs +++ b/src/format/scan.rs @@ -128,7 +128,7 @@ pub fn short_or_long_month0(s: &str) -> ParseResult<(&str, u8)> { pub fn short_or_long_weekday(s: &str) -> ParseResult<(&str, Weekday)> { // lowercased weekday names, minus first three chars static LONG_WEEKDAY_SUFFIXES: [&'static str; 7] = - ["day", "sday", "nesday", "rsday", "day", "urday", "sunday"]; + ["day", "sday", "nesday", "rsday", "day", "urday", "day"]; let (mut s, weekday) = try!(short_weekday(s)); From 097ab04a69b0ab147904a401034f341cd09ebb4a Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Mon, 28 Mar 2016 09:57:29 -0700 Subject: [PATCH 3/3] Update RFC850 test to check all weekdays --- src/format/parse.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/format/parse.rs b/src/format/parse.rs index 316cfac..13c44ab 100644 --- a/src/format/parse.rs +++ b/src/format/parse.rs @@ -652,6 +652,21 @@ fn parse_rfc850() { // Check that it parses correctly assert_eq!(Ok(dt), UTC.datetime_from_str("Sunday, 06-Nov-94 08:49:37 GMT", RFC850_FMT)); + + // Check that the rest of the weekdays parse correctly (this test originally failed because + // Sunday parsed incorrectly). + let testdates = [ + (UTC.ymd(1994, 11, 7).and_hms(8, 49, 37), "Monday, 07-Nov-94 08:49:37 GMT"), + (UTC.ymd(1994, 11, 8).and_hms(8, 49, 37), "Tuesday, 08-Nov-94 08:49:37 GMT"), + (UTC.ymd(1994, 11, 9).and_hms(8, 49, 37), "Wednesday, 09-Nov-94 08:49:37 GMT"), + (UTC.ymd(1994, 11, 10).and_hms(8, 49, 37), "Thursday, 10-Nov-94 08:49:37 GMT"), + (UTC.ymd(1994, 11, 11).and_hms(8, 49, 37), "Friday, 11-Nov-94 08:49:37 GMT"), + (UTC.ymd(1994, 11, 12).and_hms(8, 49, 37), "Saturday, 12-Nov-94 08:49:37 GMT"), + ]; + + for val in &testdates { + assert_eq!(Ok(val.0), UTC.datetime_from_str(val.1, RFC850_FMT)); + } } #[cfg(test)]