-
Notifications
You must be signed in to change notification settings - Fork 1
/
TimeStamp.h
executable file
·55 lines (44 loc) · 1.35 KB
/
TimeStamp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef TIME_STAMP_H
#define TIME_STAMP_H
#include "common.h"
class TimeStamp
{
public:
TimeStamp();
TimeStamp(int64_t microSecondsSinceEpochArg)
: microsecondsSinceEpoch(microSecondsSinceEpochArg)
{
}
std::string toString() const;
int64_t getMicrosecondsSinceEpoch() { return microsecondsSinceEpoch; }
static TimeStamp now();
static const int kMicroSecondsPerSecond = 1000 * 1000;
private:
int64_t microsecondsSinceEpoch;
};
inline bool operator<(TimeStamp lts,TimeStamp rts)
{
return lts.getMicrosecondsSinceEpoch() < rts.getMicrosecondsSinceEpoch();
}
inline bool operator>(TimeStamp lts,TimeStamp rts)
{
return lts.getMicrosecondsSinceEpoch() > rts.getMicrosecondsSinceEpoch();
}
inline bool operator==(TimeStamp lts,TimeStamp rts)
{
return lts.getMicrosecondsSinceEpoch() == rts.getMicrosecondsSinceEpoch();
}
inline bool operator!=(TimeStamp lts,TimeStamp rts)
{
return lts.getMicrosecondsSinceEpoch() != rts.getMicrosecondsSinceEpoch();
}
inline double timeDifference(TimeStamp high, TimeStamp low)
{
int64_t diff = high.getMicrosecondsSinceEpoch() - low.getMicrosecondsSinceEpoch();
return static_cast<double>(diff);
}
inline TimeStamp addTime(TimeStamp timestamp, double microSeconds)
{
return TimeStamp(timestamp.getMicrosecondsSinceEpoch() + microSeconds);
}
#endif // TIME_STAMP_H