-
Notifications
You must be signed in to change notification settings - Fork 0
/
timestamp.h
53 lines (49 loc) · 1.45 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
#ifndef TIMESTAMP_H
#define TIMESTAMP_H
#include <sys/time.h>
#include <cstddef>
typedef long long int64;
class Timestamp {
public:
Timestamp()
: _microSeconds(0)
{}
Timestamp(int64 microSeconds)
: _microSeconds(microSeconds)
{}
int64 microSeconds() { return _microSeconds; }
bool valid() { return _microSeconds > 0; }
static Timestamp now();
static const int64 kMicroSecondsPerSecond = 1000 * 1000;
private:
int64 _microSeconds;
};
bool operator<(Timestamp lhs, Timestamp rhs);
bool operator==(Timestamp lhs, Timestamp rhs);
int64 operator-(Timestamp high, Timestamp low);
Timestamp operator+(Timestamp high, Timestamp low);
Timestamp operator+(Timestamp high, int seconds);
// inline bool operator<(Timestamp lhs, Timestamp rhs) {
// return lhs.microSeconds() < rhs.microSeconds();
// }
//
// inline bool operator==(Timestamp lhs, Timestamp rhs) {
// return lhs.microSeconds() == rhs.microSeconds();
// }
//
// inline int64 operator-(Timestamp high, Timestamp low) {
// return static_cast<int64>(high.microSeconds() - low.microSeconds());
// }
//
// Timestamp Timestamp::now() {
// // struct timeval {
// // time_t tv_sec; /* seconds */
// // suseconds_t tv_usec; /* microseconds */
// // };
//
// struct timeval tv;
// gettimeofday(&tv, NULL);
// int64 secs = tv.tv_sec;
// return Timestamp(secs * Timestamp::kMicroSecondsPerSecond + tv.tv_usec);
// }
#endif