mirror of https://github.com/aria2/aria2
2010-10-05 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Supported ANSI C's asctime() format in Time::parseHTTPDate(). Added Time::parseAsctime(). Changed order of application of parse functions. I could not remember why parseRFC850() was tried first. * src/TimeA2.cc * src/TimeA2.h * test/TimeTest.ccpull/1/head
parent
5db7b123b5
commit
9b1280f7a3
|
@ -1,3 +1,12 @@
|
|||
2010-10-05 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Supported ANSI C's asctime() format in Time::parseHTTPDate().
|
||||
Added Time::parseAsctime(). Changed order of application of parse
|
||||
functions. I could not remember why parseRFC850() was tried first.
|
||||
* src/TimeA2.cc
|
||||
* src/TimeA2.h
|
||||
* test/TimeTest.cc
|
||||
|
||||
2010-10-04 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Use inet_ntoa if inet_ntop is not available. Since inet_ntoa does
|
||||
|
|
|
@ -213,11 +213,17 @@ Time Time::parseRFC850Ext(const std::string& datetime)
|
|||
return parse(datetime, "%a, %d-%b-%Y %H:%M:%S GMT");
|
||||
}
|
||||
|
||||
Time Time::parseAsctime(const std::string& datetime)
|
||||
{
|
||||
return parse(datetime, "%a %b %d %H:%M:%S %Y");
|
||||
}
|
||||
|
||||
Time Time::parseHTTPDate(const std::string& datetime)
|
||||
{
|
||||
Time (*funcs[])(const std::string&) = {
|
||||
&parseRFC850,
|
||||
&parseRFC1123,
|
||||
&parseRFC850,
|
||||
&parseAsctime,
|
||||
&parseRFC850Ext,
|
||||
};
|
||||
for(Time (**funcsp)(const std::string&) = &funcs[0];
|
||||
|
|
15
src/TimeA2.h
15
src/TimeA2.h
|
@ -123,12 +123,19 @@ public:
|
|||
// Currently timezone is assumed to GMT.
|
||||
static Time parseRFC850(const std::string& datetime);
|
||||
|
||||
// Currently timezone is assumed to GMT.
|
||||
// Basically the format is RFC850, but year part is 4digit, eg 2008
|
||||
// Currently timezone is assumed to GMT. Basically the format is
|
||||
// RFC850, but year part is 4digit, eg 2008 This format appears in
|
||||
// original Netscape's PERSISTENT CLIENT STATE HTTP COOKIES
|
||||
// Specification. http://curl.haxx.se/rfc/cookie_spec.html
|
||||
static Time parseRFC850Ext(const std::string& datetime);
|
||||
|
||||
// Try parseRFC1123, parseRFC850Ex, parseRFC850 in that order and returns
|
||||
// the first "good" Time object returned by these functions.
|
||||
// Currently timezone is assumed to GMT.
|
||||
// ANSI C's asctime() format
|
||||
static Time parseAsctime(const std::string& datetime);
|
||||
|
||||
// Try parseRFC1123, parseRFC850, parseAsctime, parseRFC850Ext in
|
||||
// that order and returns the first "good" Time object returned by
|
||||
// these functions.
|
||||
static Time parseHTTPDate(const std::string& datetime);
|
||||
|
||||
static Time null();
|
||||
|
|
|
@ -15,6 +15,7 @@ class TimeTest:public CppUnit::TestFixture {
|
|||
CPPUNIT_TEST(testParseRFC1123);
|
||||
CPPUNIT_TEST(testParseRFC850);
|
||||
CPPUNIT_TEST(testParseRFC850Ext);
|
||||
CPPUNIT_TEST(testParseAsctime);
|
||||
CPPUNIT_TEST(testParseHTTPDate);
|
||||
CPPUNIT_TEST(testOperatorLess);
|
||||
CPPUNIT_TEST(testElapsed);
|
||||
|
@ -28,6 +29,7 @@ public:
|
|||
void testParseRFC1123();
|
||||
void testParseRFC850();
|
||||
void testParseRFC850Ext();
|
||||
void testParseAsctime();
|
||||
void testParseHTTPDate();
|
||||
void testOperatorLess();
|
||||
void testElapsed();
|
||||
|
@ -55,6 +57,12 @@ void TimeTest::testParseRFC850Ext()
|
|||
CPPUNIT_ASSERT_EQUAL((time_t)1220714793, t1.getTime());
|
||||
}
|
||||
|
||||
void TimeTest::testParseAsctime()
|
||||
{
|
||||
Time t1 = Time::parseAsctime("Sun Sep 6 15:26:33 2008");
|
||||
CPPUNIT_ASSERT_EQUAL((time_t)1220714793, t1.getTime());
|
||||
}
|
||||
|
||||
void TimeTest::testParseHTTPDate()
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL((time_t)1220714793,
|
||||
|
@ -66,6 +74,9 @@ void TimeTest::testParseHTTPDate()
|
|||
CPPUNIT_ASSERT_EQUAL((time_t)1220714793,
|
||||
Time::parseHTTPDate
|
||||
("Sat, 06-Sep-08 15:26:33 GMT").getTime());
|
||||
CPPUNIT_ASSERT_EQUAL((time_t)1220714793,
|
||||
Time::parseHTTPDate
|
||||
("Sun Sep 6 15:26:33 2008").getTime());
|
||||
CPPUNIT_ASSERT(Time::parseHTTPDate
|
||||
("Sat, 2008-09-06 15:26:33 GMT").bad());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue