2 This file is part of libmspcore
3 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
4 Distributed under the LGPL
6 #ifndef MSP_TIME_TIMESTAMP_H_
7 #define MSP_TIME_TIMESTAMP_H_
16 Represents a moment in time. The main source of TimeStamps is the now()
19 For representing user-specified times, use the DateTime class.
25 Construct a TimeStamp that represents an arbitarily distant point in the
26 past. It's guaranteed to be less than any valid timestamp.
28 TimeStamp(): usec(0) { }
31 Constructs a TimeStamp from a plain number. The purpose of this is to allow
32 serialization together with the raw() function.
34 explicit TimeStamp(RawTime u): usec(u) { }
37 Returns the raw number stored inside the TimeStamp. This value should be
38 considered opaque and only be used for serialization.
40 RawTime raw() const { return usec; }
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); }
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 bool operator!=(const TimeStamp &t) const { return usec!=t.usec; }
53 operator const void *() const { return usec>0 ? this : 0; }
55 static TimeStamp from_unixtime(time_t t) { return TimeStamp(t*1000000LL); }