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.
23 Construct a TimeStamp that represents an arbitarily distant point in the
24 past. It's guaranteed to be less than any valid timestamp.
26 TimeStamp(): usec(0) { }
29 Constructs a TimeStamp from a plain number. The purpose of this is to allow
30 serialization together with the raw() function.
32 explicit TimeStamp(RawTime u): usec(u) { }
35 Returns the raw number stored inside the TimeStamp. This value should be
36 considered opaque and only be used for serialization.
38 RawTime raw() const { return usec; }
40 time_t to_unixtime() const { return usec/1000000LL; }
42 TimeStamp operator+(const TimeDelta &t) const { return TimeStamp(usec+t.raw()); }
43 TimeStamp &operator+=(const TimeDelta &t) { usec+=t.raw(); return *this; }
44 TimeStamp operator-(const TimeDelta &t) const { return TimeStamp(usec-t.raw()); }
45 TimeStamp &operator-=(const TimeDelta &t) { usec-=t.raw(); return *this; }
46 TimeDelta operator-(const TimeStamp &t) const { return TimeDelta(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 bool operator==(const TimeStamp &t) const { return usec==t.usec; }
53 bool operator!=(const TimeStamp &t) const { return usec!=t.usec; }
55 operator const void *() const { return usec>0 ? this : 0; }
58 operator timeval() const { return rawtime_to_timeval(usec); }
59 operator timespec() const { return rawtime_to_timespec(usec); }
62 static TimeStamp from_unixtime(time_t t) { return TimeStamp(t*1000000LL); }