1 #ifndef MSP_TIME_TIMESTAMP_H_
2 #define MSP_TIME_TIMESTAMP_H_
11 Represents a moment in time. The main source of TimeStamps is the now()
14 For representing user-specified times, use the DateTime class.
22 /** Construct a TimeStamp that represents an arbitarily distant point in the
23 past. It's guaranteed to be less than any valid timestamp. */
24 TimeStamp(): usec(0) { }
26 /** Constructs a TimeStamp from a plain number. The purpose of this is to allow
27 serialization together with the raw() function. */
28 explicit TimeStamp(RawTime u): usec(u) { }
30 /** Returns the raw number stored inside the TimeStamp. This value should be
31 considered opaque and only be used for serialization. */
32 RawTime raw() const { return usec; }
34 time_t to_unixtime() const { return usec/1000000LL; }
36 TimeStamp operator+(const TimeDelta &t) const { return TimeStamp(usec+t.raw()); }
37 TimeStamp &operator+=(const TimeDelta &t) { usec += t.raw(); return *this; }
38 TimeStamp operator-(const TimeDelta &t) const { return TimeStamp(usec-t.raw()); }
39 TimeStamp &operator-=(const TimeDelta &t) { usec -= t.raw(); return *this; }
40 TimeDelta operator-(const TimeStamp &t) const { return TimeDelta(usec-t.usec); }
42 bool operator>=(const TimeStamp &t) const { return usec>=t.usec; }
43 bool operator>(const TimeStamp &t) const { return usec>t.usec; }
44 bool operator<=(const TimeStamp &t) const { return usec<=t.usec; }
45 bool operator<(const TimeStamp &t) const { return 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; }
49 operator const void *() const { return usec>0 ? this : 0; }
51 static TimeStamp from_unixtime(time_t t) { return TimeStamp(t*1000000LL); }