|
|
@ -22,19 +22,19 @@ using namespace chrono; |
|
|
|
template <class T> |
|
|
|
class T_TimeUtil { |
|
|
|
public: |
|
|
|
time_point<T> zero() { return time_point<T>(nanoseconds(0)); } |
|
|
|
time_point<T> now() { return move(T::now()); } |
|
|
|
int64_t getus() { return duration_cast<microseconds>(T::now().time_since_epoch()).count(); } |
|
|
|
int64_t gets() { return duration_cast<seconds>(T::now().time_since_epoch()).count(); } |
|
|
|
int64_t getms() { return duration_cast<milliseconds>(T::now().time_since_epoch()).count(); } |
|
|
|
int64_t geth() { return duration_cast<hours>(T::now().time_since_epoch()).count(); } |
|
|
|
int64_t tpToMs(time_point<T> t) { return duration_cast<milliseconds>(t.time_since_epoch()).count(); } |
|
|
|
int64_t tpToUs(time_point<T> t) { return duration_cast<microseconds>(t.time_since_epoch()).count(); } |
|
|
|
int64_t tpToS(time_point<T> t) { return duration_cast<seconds>(t.time_since_epoch()).count(); } |
|
|
|
int64_t dToMs(nanoseconds ns) { return duration_cast<milliseconds>(ns).count(); } |
|
|
|
int64_t dToUs(nanoseconds ns) { return duration_cast<microseconds>(ns).count(); } |
|
|
|
int64_t dToS(nanoseconds ns) { return duration_cast<seconds>(ns).count(); } |
|
|
|
int64_t dToNs(nanoseconds ns) { return ns.count(); } |
|
|
|
time_point<T> zero() { return time_point<T>(nanoseconds(0)); } |
|
|
|
time_point<T> now() { return move(T::now()); } |
|
|
|
int64_t getus() { return duration_cast<microseconds>(T::now().time_since_epoch()).count(); } |
|
|
|
int64_t gets() { return duration_cast<seconds>(T::now().time_since_epoch()).count(); } |
|
|
|
int64_t getms() { return duration_cast<milliseconds>(T::now().time_since_epoch()).count(); } |
|
|
|
int64_t geth() { return duration_cast<hours>(T::now().time_since_epoch()).count(); } |
|
|
|
int64_t tpToMs(time_point<T> t) { return duration_cast<milliseconds>(t.time_since_epoch()).count(); } |
|
|
|
int64_t tpToUs(time_point<T> t) { return duration_cast<microseconds>(t.time_since_epoch()).count(); } |
|
|
|
int64_t tpToS(time_point<T> t) { return duration_cast<seconds>(t.time_since_epoch()).count(); } |
|
|
|
int64_t dToMs(nanoseconds ns) { return duration_cast<milliseconds>(ns).count(); } |
|
|
|
int64_t dToUs(nanoseconds ns) { return duration_cast<microseconds>(ns).count(); } |
|
|
|
int64_t dToS(nanoseconds ns) { return duration_cast<seconds>(ns).count(); } |
|
|
|
int64_t dToNs(nanoseconds ns) { return ns.count(); } |
|
|
|
inline time_point<T> msToTp(int64_t ms) { |
|
|
|
time_point<T> tp = time_point<T>(milliseconds(ms)); |
|
|
|
return move(tp); |
|
|
@ -48,7 +48,7 @@ class T_TimeUtil { |
|
|
|
inline time_point<T> adds(int value) { return adds(T::now(), value); } |
|
|
|
inline time_point<T> addms(int value) { return addms(T::now(), value); } |
|
|
|
inline time_point<T> addus(int value) { return addus(T::now(), value); } |
|
|
|
inline int64_t ms2us(int64_t ms) { return ms * 1000; } |
|
|
|
inline int64_t ms2us(int64_t ms) { return ms * 1000; } |
|
|
|
/**
|
|
|
|
* @brief 计算流逝时间 |
|
|
|
*/ |
|
|
@ -68,11 +68,16 @@ class T_TimeUtil { |
|
|
|
int64_t countdownTimeNs(time_point<T> endtime) { return dToNs(endtime - T::now()); } |
|
|
|
}; |
|
|
|
|
|
|
|
typedef T_TimeUtil<system_clock> tu_sys; |
|
|
|
typedef T_TimeUtil<steady_clock> tu_steady; |
|
|
|
typedef T_TimeUtil<system_clock> tu_sys; // not use in future
|
|
|
|
typedef T_TimeUtil<steady_clock> tu_steady; // not use in future
|
|
|
|
typedef time_point<system_clock> tp_sys; // not use in future
|
|
|
|
typedef time_point<steady_clock> tp_steady; // not use in future
|
|
|
|
|
|
|
|
typedef time_point<system_clock> tp_sys; |
|
|
|
typedef time_point<steady_clock> tp_steady; |
|
|
|
// new api name
|
|
|
|
typedef T_TimeUtil<system_clock> zsystem_clock; |
|
|
|
typedef T_TimeUtil<steady_clock> zsteady_clock; |
|
|
|
|
|
|
|
typedef time_point<system_clock> zsystem_tp; |
|
|
|
typedef time_point<steady_clock> zsteady_tp; |
|
|
|
}; // namespace core
|
|
|
|
} // namespace iflytop
|