]> git.tdb.fi Git - libs/core.git/blobdiff - source/time/timedelta.h
Add negation operator and abs function for TimeDelta
[libs/core.git] / source / time / timedelta.h
index c73529b0e3f8a9c7ea60bdcc215ce105050643fc..2ce6eeb4e9e42d3d48db4a6d908d0c18c480810c 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef MSP_TIME_TIMEDELTA_H_
 #define MSP_TIME_TIMEDELTA_H_
 
+#include <cstdlib>
 #include <ctime>
 #include <msp/strings/lexicalcast.h>
 #include "rawtime.h"
@@ -32,6 +33,7 @@ public:
        TimeDelta &operator+=(const TimeDelta &t) { usec += t.usec; return *this; }
        TimeDelta operator-(const TimeDelta &t) const { return TimeDelta(usec-t.usec); }
        TimeDelta &operator-=(const TimeDelta &t) { usec -= t.usec; return *this; }
+       TimeDelta operator-() const { return TimeDelta(-usec); }
 
        template<typename T>
        TimeDelta operator*(T a) const { return TimeDelta(RawTime(usec*a)); }
@@ -71,6 +73,9 @@ extern const TimeDelta hour;
 extern const TimeDelta day;
 extern const TimeDelta week;
 
+inline TimeDelta abs(const TimeDelta &t) { return t>=zero ? t : -t; }
+using std::abs;
+
 } // namespace Time
 } // namespace Msp