Support HTTP date ending "+0000" as well as "GMT".

pull/331/head
Tatsuhiro Tsujikawa 2015-01-26 21:31:47 +09:00
parent b5f22ba216
commit d5d21d20d7
3 changed files with 17 additions and 0 deletions

View File

@ -203,6 +203,11 @@ Time Time::parseRFC1123(const std::string& datetime)
return parse(datetime, "%a, %d %b %Y %H:%M:%S GMT");
}
Time Time::parseRFC1123Alt(const std::string& datetime)
{
return parse(datetime, "%a, %d %b %Y %H:%M:%S +0000");
}
Time Time::parseRFC850(const std::string& datetime)
{
return parse(datetime, "%a, %d-%b-%y %H:%M:%S GMT");
@ -222,6 +227,7 @@ Time Time::parseHTTPDate(const std::string& datetime)
{
Time (*funcs[])(const std::string&) = {
&parseRFC1123,
&parseRFC1123Alt,
&parseRFC850,
&parseAsctime,
&parseRFC850Ext,

View File

@ -120,6 +120,10 @@ public:
// Currently timezone is assumed to GMT.
static Time parseRFC1123(const std::string& datetime);
// Like parseRFC1123, but only accepts trailing "+0000" instead of
// last 3 letters "GMT".
static Time parseRFC1123Alt(const std::string& datetime);
// Currently timezone is assumed to GMT.
static Time parseRFC850(const std::string& datetime);

View File

@ -27,6 +27,7 @@ public:
void tearDown() {}
void testParseRFC1123();
void testParseRFC1123Alt();
void testParseRFC850();
void testParseRFC850Ext();
void testParseAsctime();
@ -45,6 +46,12 @@ void TimeTest::testParseRFC1123()
CPPUNIT_ASSERT_EQUAL((time_t)1220714793, t1.getTime());
}
void TimeTest::testParseRFC1123Alt()
{
Time t1 = Time::parseRFC1123Alt("Sat, 06 Sep 2008 15:26:33 +0000");
CPPUNIT_ASSERT_EQUAL((time_t)1220714793, t1.getTime());
}
void TimeTest::testParseRFC850()
{
Time t1 = Time::parseRFC850("Saturday, 06-Sep-08 15:26:33 GMT");