2008-09-07 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Added a constuctor that receives struct timeval.
	Added operator<.
	* src/TimeA2.cc
	* src/TimeA2.h
	* test/TimeTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2008-09-07 04:57:31 +00:00
parent b624a12ed0
commit 5fb94a3af0
4 changed files with 42 additions and 2 deletions

View File

@ -1,3 +1,11 @@
2008-09-07 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added a constuctor that receives struct timeval.
Added operator<.
* src/TimeA2.cc
* src/TimeA2.h
* test/TimeTest.cc
2008-09-07 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Parse `expires' of Set-Cookie using Time::parseHTTPDate()

View File

@ -52,6 +52,10 @@ Time::Time(time_t sec) {
setTimeInSec(sec);
}
Time::Time(const struct timeval& tv) {
this->tv = tv;
}
Time::~Time() {}
Time& Time::operator=(const Time& time)
@ -62,6 +66,11 @@ Time& Time::operator=(const Time& time)
return *this;
}
bool Time::operator<(const Time& time) const
{
return Util::difftv(time.tv, tv) > 0;
}
void Time::reset() {
gettimeofday(&tv, 0);
}
@ -191,5 +200,5 @@ Time Time::parseHTTPDate(const std::string& datetime)
}
return Time(-1);
}
} // namespace aria2

View File

@ -53,10 +53,13 @@ public:
Time();
Time(const Time& time);
Time(time_t sec);
Time(const struct timeval& tv);
~Time();
Time& operator=(const Time& time);
~Time();
bool operator<(const Time& time) const;
// Makes this object's time value up to date.
void reset();

View File

@ -13,6 +13,7 @@ class TimeTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testParseRFC850);
CPPUNIT_TEST(testParseRFC850Ext);
CPPUNIT_TEST(testParseHTTPDate);
CPPUNIT_TEST(testOperatorLess);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {}
@ -23,6 +24,7 @@ public:
void testParseRFC850();
void testParseRFC850Ext();
void testParseHTTPDate();
void testOperatorLess();
};
@ -62,4 +64,22 @@ void TimeTest::testParseHTTPDate()
("Sat, 2008-09-06 15:26:33 GMT").getTime());
}
void TimeTest::testOperatorLess()
{
CPPUNIT_ASSERT(Time(1) < Time(2));
CPPUNIT_ASSERT(!(Time(1) < Time(1)));
CPPUNIT_ASSERT(!(Time(2) < Time(1)));
struct timeval tv1;
tv1.tv_sec = 0;
tv1.tv_usec = 1;
struct timeval tv2;
tv2.tv_sec = 1;
tv2.tv_usec = 0;
CPPUNIT_ASSERT(Time(tv1) < Time(tv2));
tv2.tv_sec = 0;
CPPUNIT_ASSERT(Time(tv2) < Time(tv1));
}
} // namespace aria2