Merge pull request #66 from jwilm/fix-parse-rfc-850

Fix parsing LongWeekday when day is Sunday
This commit is contained in:
Kang Seonghoon 2016-03-29 03:02:59 +09:00
commit ada7aeda72
2 changed files with 35 additions and 1 deletions

View File

@ -635,6 +635,40 @@ 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));
// 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)]
#[test]
fn test_rfc3339() {

View File

@ -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));