Represents an instant in time.
| 21 | |
| 22 | // Represents an instant in time. |
| 23 | class Time |
| 24 | { |
| 25 | public: |
| 26 | // Constructs a time at the Epoch. It is needed because collections |
| 27 | // (e.g., std::map) require a default constructor to construct |
| 28 | // empty values. |
| 29 | Time() : sinceEpoch(Duration::zero()) {} |
| 30 | |
| 31 | static Time epoch(); |
| 32 | static Time max(); |
| 33 | |
| 34 | static Try<Time> create(double seconds); |
| 35 | |
| 36 | Duration duration() const { return sinceEpoch; } |
| 37 | |
| 38 | double secs() const { return sinceEpoch.secs(); } |
| 39 | |
| 40 | bool operator<(const Time& t) const { return sinceEpoch < t.sinceEpoch; } |
| 41 | bool operator<=(const Time& t) const { return sinceEpoch <= t.sinceEpoch; } |
| 42 | bool operator>(const Time& t) const { return sinceEpoch > t.sinceEpoch; } |
| 43 | bool operator>=(const Time& t) const { return sinceEpoch >= t.sinceEpoch; } |
| 44 | bool operator==(const Time& t) const { return sinceEpoch == t.sinceEpoch; } |
| 45 | bool operator!=(const Time& t) const { return sinceEpoch != t.sinceEpoch; } |
| 46 | |
| 47 | Time& operator+=(const Duration& d) |
| 48 | { |
| 49 | sinceEpoch += d; |
| 50 | return *this; |
| 51 | } |
| 52 | |
| 53 | Time& operator-=(const Duration& d) |
| 54 | { |
| 55 | sinceEpoch -= d; |
| 56 | return *this; |
| 57 | } |
| 58 | |
| 59 | Duration operator-(const Time& that) const |
| 60 | { |
| 61 | return sinceEpoch - that.sinceEpoch; |
| 62 | } |
| 63 | |
| 64 | Time operator+(const Duration& duration) const |
| 65 | { |
| 66 | Time new_ = *this; |
| 67 | new_ += duration; |
| 68 | return new_; |
| 69 | } |
| 70 | |
| 71 | Time operator-(const Duration& duration) const |
| 72 | { |
| 73 | Time new_ = *this; |
| 74 | new_ -= duration; |
| 75 | return new_; |
| 76 | } |
| 77 | |
| 78 | private: |
| 79 | Duration sinceEpoch; |
| 80 |
no outgoing calls
no test coverage detected