Allow RFC822 timestamps without a week day

RFC 822 specifies the week day is optional.
This commit is contained in:
Lauri Nurmi 2022-03-09 21:41:52 +02:00
parent 8d9d2684ef
commit 1c5e66a12c
2 changed files with 22 additions and 10 deletions

View file

@ -754,17 +754,22 @@ wxDateTime::ParseRfc822Date(const wxString& originalDate, wxString::const_iterat
const wxString::const_iterator pEnd = date.end();
wxString::const_iterator p = date.begin();
// 1. week day
const wxDateTime::WeekDay
wd = GetWeekDayFromName(p, pEnd, Name_Abbr, DateLang_English);
if ( wd == Inv_WeekDay )
return false;
//else: ignore week day for now, we could also check that it really
// corresponds to the specified date
// 1. week day (optional)
// if there is a week day present, it must be separated
// by a comma at position [3].
if ( date.Length() > 3 && date[3] == ',' )
{
const wxDateTime::WeekDay
wd = GetWeekDayFromName(p, pEnd, Name_Abbr, DateLang_English);
if ( wd == Inv_WeekDay )
return false;
//else: ignore week day for now, we could also check that it really
// corresponds to the specified date
// 2. separating comma
if ( *p++ != ',' || *p++ != ' ' )
return false;
// 2. separating comma
if ( *p++ != ',' || *p++ != ' ' )
return false;
}
// 3. day number
if ( !wxIsdigit(*p) )

View file

@ -1093,6 +1093,13 @@ void DateTimeTestCase::TestParseRFC822()
true
},
// day of week is optional according to the RFC
{
"18 Dec 1999 10:48:30 -0500",
{ 18, wxDateTime::Dec, 1999, 15, 48, 30 },
true
},
// try some bogus ones too
{
"Sun, 01 Jun 2008 16:30: +0200",