Merge pull request #180 from syvex/TimestampTimespanOperators

Add operators to Timestamp for Timespan.
This commit is contained in:
Aleksandar Fabijanic
2013-05-06 14:19:12 -07:00
2 changed files with 30 additions and 0 deletions

View File

@@ -46,6 +46,7 @@
namespace Poco {
class Timespan;
class Foundation_API Timestamp
/// A Timestamp stores a monotonic* time value
@@ -95,10 +96,14 @@ public:
bool operator <= (const Timestamp& ts) const;
Timestamp operator + (TimeDiff d) const;
Timestamp operator + (const Timespan& span) const;
Timestamp operator - (TimeDiff d) const;
Timestamp operator - (const Timespan& span) const;
TimeDiff operator - (const Timestamp& ts) const;
Timestamp& operator += (TimeDiff d);
Timestamp& operator += (const Timespan& span);
Timestamp& operator -= (TimeDiff d);
Timestamp& operator -= (const Timespan& span);
std::time_t epochTime() const;
/// Returns the timestamp expressed in time_t.

View File

@@ -35,6 +35,7 @@
#include "Poco/Timestamp.h"
#include "Poco/Timespan.h"
#include "Poco/Exception.h"
#include <algorithm>
#if defined(POCO_OS_FAMILY_UNIX)
@@ -256,6 +257,30 @@ void Timestamp::update()
}
Timestamp Timestamp::operator + (const Timespan& span) const
{
return *this + span.totalMicroseconds();
}
Timestamp Timestamp::operator - (const Timespan& span) const
{
return *this - span.totalMicroseconds();
}
Timestamp& Timestamp::operator += (const Timespan& span)
{
return *this += span.totalMicroseconds();
}
Timestamp& Timestamp::operator -= (const Timespan& span)
{
return *this -= span.totalMicroseconds();
}
#if defined(_WIN32)