From 44ba01648d93ab544467a5156008f65e432f8127 Mon Sep 17 00:00:00 2001 From: Mike Naquin Date: Mon, 6 May 2013 15:29:52 -0500 Subject: [PATCH] Add operators to Timestamp for Timespan. Timestamp operator + (const Timespan& span) const; Timestamp operator - (const Timespan& span) const; Timestamp& operator += (const Timespan& span); Timestamp& operator -= (const Timespan& span); --- Foundation/include/Poco/Timestamp.h | 5 +++++ Foundation/src/Timestamp.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/Foundation/include/Poco/Timestamp.h b/Foundation/include/Poco/Timestamp.h index d2c7aa594..000b4ad33 100644 --- a/Foundation/include/Poco/Timestamp.h +++ b/Foundation/include/Poco/Timestamp.h @@ -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. diff --git a/Foundation/src/Timestamp.cpp b/Foundation/src/Timestamp.cpp index 8fb50dc32..40380d939 100644 --- a/Foundation/src/Timestamp.cpp +++ b/Foundation/src/Timestamp.cpp @@ -35,6 +35,7 @@ #include "Poco/Timestamp.h" +#include "Poco/Timespan.h" #include "Poco/Exception.h" #include #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)