3 This file is part of libmspcore
4 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #ifndef MSP_TIME_TIMESTAMP_H_
9 #define MSP_TIME_TIMESTAMP_H_
11 #include "timedelta.h"
18 Represents a moment in time. The main source of TimeStamps is the now()
21 For representing user-specified times, use the DateTime class.
30 Construct a TimeStamp that represents an arbitarily distant point in the
31 past. It's guaranteed to be less than any valid timestamp.
33 TimeStamp(): usec(0) { }
36 Constructs a TimeStamp from a plain number. The purpose of this is to allow
37 serialization together with the raw() function.
39 explicit TimeStamp(RawTime u): usec(u) { }
42 Returns the raw number stored inside the TimeStamp. This value should be
43 considered opaque and only be used for serialization.
45 RawTime raw() const { return usec; }
47 TimeStamp operator+(const TimeDelta &t) const { return TimeStamp(usec+t.raw()); }
48 TimeStamp &operator+=(const TimeDelta &t) { usec+=t.raw(); return *this; }
49 TimeStamp operator-(const TimeDelta &t) const { return TimeStamp(usec-t.raw()); }
50 TimeStamp &operator-=(const TimeDelta &t) { usec-=t.raw(); return *this; }
51 TimeDelta operator-(const TimeStamp &t) const { return TimeDelta(usec-t.usec); }
53 bool operator>=(const TimeStamp &t) const { return usec>=t.usec; }
54 bool operator>(const TimeStamp &t) const { return usec>t.usec; }
55 bool operator<=(const TimeStamp &t) const { return usec<=t.usec; }
56 bool operator<(const TimeStamp &t) const { return usec<t.usec; }
57 bool operator==(const TimeStamp &t) const { return usec==t.usec; }
58 bool operator!=(const TimeStamp &t) const { return usec!=t.usec; }
60 operator const void *() const { return usec>0 ? this : 0; }
62 static TimeStamp from_unixtime(time_t t) { return TimeStamp(t*1000000LL); }