| 1 |
// Mimic the implementation of absl::Duration |
| 2 |
namespace absl { |
| 3 |
|
| 4 |
using int64_t = long long int; |
| 5 |
|
| 6 |
class Duration { |
| 7 |
public: |
| 8 |
Duration &operator*=(int64_t r); |
| 9 |
Duration &operator*=(float r); |
| 10 |
Duration &operator*=(double r); |
| 11 |
template <typename T> Duration &operator*=(T r); |
| 12 |
|
| 13 |
Duration &operator/=(int64_t r); |
| 14 |
Duration &operator/=(float r); |
| 15 |
Duration &operator/=(double r); |
| 16 |
template <typename T> Duration &operator/=(T r); |
| 17 |
|
| 18 |
Duration &operator+(Duration d); |
| 19 |
}; |
| 20 |
|
| 21 |
template <typename T> Duration operator*(Duration lhs, T rhs); |
| 22 |
template <typename T> Duration operator*(T lhs, Duration rhs); |
| 23 |
template <typename T> Duration operator/(Duration lhs, T rhs); |
| 24 |
int64_t operator/(Duration lhs, Duration rhs); |
| 25 |
|
| 26 |
class Time{}; |
| 27 |
|
| 28 |
constexpr Duration Nanoseconds(long long); |
| 29 |
constexpr Duration Microseconds(long long); |
| 30 |
constexpr Duration Milliseconds(long long); |
| 31 |
constexpr Duration Seconds(long long); |
| 32 |
constexpr Duration Minutes(long long); |
| 33 |
constexpr Duration Hours(long long); |
| 34 |
|
| 35 |
template <typename T> struct EnableIfFloatImpl {}; |
| 36 |
template <> struct EnableIfFloatImpl<float> { typedef int Type; }; |
| 37 |
template <> struct EnableIfFloatImpl<double> { typedef int Type; }; |
| 38 |
template <> struct EnableIfFloatImpl<long double> { typedef int Type; }; |
| 39 |
template <typename T> using EnableIfFloat = typename EnableIfFloatImpl<T>::Type; |
| 40 |
|
| 41 |
template <typename T, EnableIfFloat<T> = 0> Duration Nanoseconds(T n); |
| 42 |
template <typename T, EnableIfFloat<T> = 0> Duration Microseconds(T n); |
| 43 |
template <typename T, EnableIfFloat<T> = 0> Duration Milliseconds(T n); |
| 44 |
template <typename T, EnableIfFloat<T> = 0> Duration Seconds(T n); |
| 45 |
template <typename T, EnableIfFloat<T> = 0> Duration Minutes(T n); |
| 46 |
template <typename T, EnableIfFloat<T> = 0> Duration Hours(T n); |
| 47 |
|
| 48 |
double ToDoubleHours(Duration d); |
| 49 |
double ToDoubleMinutes(Duration d); |
| 50 |
double ToDoubleSeconds(Duration d); |
| 51 |
double ToDoubleMilliseconds(Duration d); |
| 52 |
double ToDoubleMicroseconds(Duration d); |
| 53 |
double ToDoubleNanoseconds(Duration d); |
| 54 |
int64_t ToInt64Hours(Duration d); |
| 55 |
int64_t ToInt64Minutes(Duration d); |
| 56 |
int64_t ToInt64Seconds(Duration d); |
| 57 |
int64_t ToInt64Milliseconds(Duration d); |
| 58 |
int64_t ToInt64Microseconds(Duration d); |
| 59 |
int64_t ToInt64Nanoseconds(Duration d); |
| 60 |
|
| 61 |
int64_t ToUnixHours(Time t); |
| 62 |
int64_t ToUnixMinutes(Time t); |
| 63 |
int64_t ToUnixSeconds(Time t); |
| 64 |
int64_t ToUnixMillis(Time t); |
| 65 |
int64_t ToUnixMicros(Time t); |
| 66 |
int64_t ToUnixNanos(Time t); |
| 67 |
Time FromUnixHours(int64_t); |
| 68 |
Time FromUnixMinutes(int64_t); |
| 69 |
Time FromUnixSeconds(int64_t); |
| 70 |
Time FromUnixMillis(int64_t); |
| 71 |
Time FromUnixMicros(int64_t); |
| 72 |
Time FromUnixNanos(int64_t); |
| 73 |
|
| 74 |
Time Now(); |
| 75 |
|
| 76 |
// Relational Operators |
| 77 |
constexpr bool operator<(Duration lhs, Duration rhs); |
| 78 |
constexpr bool operator>(Duration lhs, Duration rhs); |
| 79 |
constexpr bool operator>=(Duration lhs, Duration rhs); |
| 80 |
constexpr bool operator<=(Duration lhs, Duration rhs); |
| 81 |
constexpr bool operator==(Duration lhs, Duration rhs); |
| 82 |
constexpr bool operator!=(Duration lhs, Duration rhs); |
| 83 |
|
| 84 |
// Additive Operators |
| 85 |
inline Time operator+(Time lhs, Duration rhs); |
| 86 |
inline Time operator+(Duration lhs, Time rhs); |
| 87 |
inline Time operator-(Time lhs, Duration rhs); |
| 88 |
inline Duration operator-(Time lhs, Time rhs); |
| 89 |
|
| 90 |
double FDivDuration(Duration num, Duration den); |
| 91 |
|
| 92 |
} // namespace absl |