2 This file is part of libmspframework
3 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
4 Distributed under the LGPL
6 #ifndef MSP_TIME_TIMESTAMP_H_
7 #define MSP_TIME_TIMESTAMP_H_
10 #include "timedelta.h"
16 Represents a moment in time, such as the last tick. This class is NOT intended
17 to be used for storing arbitary user-defined times, I'll add a DateTime class
24 Construct a TimeStamp that represents an arbitarily distant point in the
25 past. It's guaranteed to be less than any valid timestamp.
27 TimeStamp(): usec(0) { }
30 Constructs a TimeStamp from a plain number. The purpose of this is to allow
31 serialization together with the raw() function.
33 explicit TimeStamp(int64_t u): usec(u) { }
36 Returns the raw number stored inside the TimeStamp. This should only be used
37 for serialization and the result should not be interpreted in any way.
39 int64_t raw() const { return usec; }
41 TimeStamp operator+(const TimeDelta &t) const { return TimeStamp(usec+t.raw()); }
42 TimeStamp &operator+=(const TimeDelta &t) { usec+=t.raw(); return *this; }
43 TimeStamp operator-(const TimeDelta &t) const { return TimeStamp(usec-t.raw()); }
44 TimeStamp &operator-=(const TimeDelta &t) { usec-=t.raw(); return *this; }
45 TimeDelta operator-(const TimeStamp &t) const { return TimeDelta(usec-t.usec); }
46 bool operator>=(const TimeStamp &t) const { return usec>=t.usec; }
47 bool operator>(const TimeStamp &t) const { return usec>t.usec; }
48 bool operator<=(const TimeStamp &t) const { return usec<=t.usec; }
49 bool operator<(const TimeStamp &t) const { return usec<t.usec; }
50 bool operator==(const TimeStamp &t) const { return usec==t.usec; }
51 bool operator!=(const TimeStamp &t) const { return usec!=t.usec; }
52 operator bool() const { return usec>0; }
54 static TimeStamp from_unixtime(time_t t) { return TimeStamp(t*1000000LL); }