time.h
3.11 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Mimic the implementation of absl::Duration
namespace absl {
using int64_t = long long int;
class Duration {
public:
Duration &operator*=(int64_t r);
Duration &operator*=(float r);
Duration &operator*=(double r);
template <typename T> Duration &operator*=(T r);
Duration &operator/=(int64_t r);
Duration &operator/=(float r);
Duration &operator/=(double r);
template <typename T> Duration &operator/=(T r);
Duration &operator+(Duration d);
};
template <typename T> Duration operator*(Duration lhs, T rhs);
template <typename T> Duration operator*(T lhs, Duration rhs);
template <typename T> Duration operator/(Duration lhs, T rhs);
int64_t operator/(Duration lhs, Duration rhs);
class Time{};
constexpr Duration Nanoseconds(long long);
constexpr Duration Microseconds(long long);
constexpr Duration Milliseconds(long long);
constexpr Duration Seconds(long long);
constexpr Duration Minutes(long long);
constexpr Duration Hours(long long);
template <typename T> struct EnableIfFloatImpl {};
template <> struct EnableIfFloatImpl<float> { typedef int Type; };
template <> struct EnableIfFloatImpl<double> { typedef int Type; };
template <> struct EnableIfFloatImpl<long double> { typedef int Type; };
template <typename T> using EnableIfFloat = typename EnableIfFloatImpl<T>::Type;
template <typename T, EnableIfFloat<T> = 0> Duration Nanoseconds(T n);
template <typename T, EnableIfFloat<T> = 0> Duration Microseconds(T n);
template <typename T, EnableIfFloat<T> = 0> Duration Milliseconds(T n);
template <typename T, EnableIfFloat<T> = 0> Duration Seconds(T n);
template <typename T, EnableIfFloat<T> = 0> Duration Minutes(T n);
template <typename T, EnableIfFloat<T> = 0> Duration Hours(T n);
double ToDoubleHours(Duration d);
double ToDoubleMinutes(Duration d);
double ToDoubleSeconds(Duration d);
double ToDoubleMilliseconds(Duration d);
double ToDoubleMicroseconds(Duration d);
double ToDoubleNanoseconds(Duration d);
int64_t ToInt64Hours(Duration d);
int64_t ToInt64Minutes(Duration d);
int64_t ToInt64Seconds(Duration d);
int64_t ToInt64Milliseconds(Duration d);
int64_t ToInt64Microseconds(Duration d);
int64_t ToInt64Nanoseconds(Duration d);
int64_t ToUnixHours(Time t);
int64_t ToUnixMinutes(Time t);
int64_t ToUnixSeconds(Time t);
int64_t ToUnixMillis(Time t);
int64_t ToUnixMicros(Time t);
int64_t ToUnixNanos(Time t);
Time FromUnixHours(int64_t);
Time FromUnixMinutes(int64_t);
Time FromUnixSeconds(int64_t);
Time FromUnixMillis(int64_t);
Time FromUnixMicros(int64_t);
Time FromUnixNanos(int64_t);
Time Now();
// Relational Operators
constexpr bool operator<(Duration lhs, Duration rhs);
constexpr bool operator>(Duration lhs, Duration rhs);
constexpr bool operator>=(Duration lhs, Duration rhs);
constexpr bool operator<=(Duration lhs, Duration rhs);
constexpr bool operator==(Duration lhs, Duration rhs);
constexpr bool operator!=(Duration lhs, Duration rhs);
// Additive Operators
inline Time operator+(Time lhs, Duration rhs);
inline Time operator+(Duration lhs, Time rhs);
inline Time operator-(Time lhs, Duration rhs);
inline Duration operator-(Time lhs, Time rhs);
double FDivDuration(Duration num, Duration den);
} // namespace absl