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_
10 #include "timedelta.h"
17 Represents a moment in time. The main source of TimeStamps is the now()
20 For representing user-specified times, use the DateTime class.
26 Construct a TimeStamp that represents an arbitarily distant point in the
27 past. It's guaranteed to be less than any valid timestamp.
29 TimeStamp(): usec(0) { }
32 Constructs a TimeStamp from a plain number. The purpose of this is to allow
33 serialization together with the raw() function.
35 explicit TimeStamp(RawTime u): usec(u) { }
38 Returns the raw number stored inside the TimeStamp. This value should be
39 considered opaque and only be used for serialization.
41 RawTime raw() const { return usec; }
43 TimeStamp operator+(const TimeDelta &t) const { return TimeStamp(usec+t.raw()); }
44 TimeStamp &operator+=(const TimeDelta &t) { usec+=t.raw(); return *this; }
45 TimeStamp operator-(const TimeDelta &t) const { return TimeStamp(usec-t.raw()); }
46 TimeStamp &operator-=(const TimeDelta &t) { usec-=t.raw(); return *this; }
47 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; }
54 operator bool() const { return usec>0; }
56 static TimeStamp from_unixtime(time_t t) { return TimeStamp(t*1000000LL); }