|
|
@ -22,19 +22,19 @@ using namespace chrono; |
|
|
|
template <class T> |
|
|
|
class T_TimeUtils { |
|
|
|
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(); } |
|
|
|
static int64_t tpToMs(time_point<T> t) { return duration_cast<milliseconds>(t.time_since_epoch()).count(); } |
|
|
|
static int64_t tpToUs(time_point<T> t) { return duration_cast<microseconds>(t.time_since_epoch()).count(); } |
|
|
|
static int64_t tpToS(time_point<T> t) { return duration_cast<seconds>(t.time_since_epoch()).count(); } |
|
|
|
static int64_t dToMs(nanoseconds ns) { return duration_cast<milliseconds>(ns).count(); } |
|
|
|
static int64_t dToUs(nanoseconds ns) { return duration_cast<microseconds>(ns).count(); } |
|
|
|
static int64_t dToS(nanoseconds ns) { return duration_cast<seconds>(ns).count(); } |
|
|
|
static 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(); } |
|
|
|
static int64_t tpToMs(time_point<T> t) { return duration_cast<milliseconds>(t.time_since_epoch()).count(); } |
|
|
|
static int64_t tpToUs(time_point<T> t) { return duration_cast<microseconds>(t.time_since_epoch()).count(); } |
|
|
|
static int64_t tpToS(time_point<T> t) { return duration_cast<seconds>(t.time_since_epoch()).count(); } |
|
|
|
static int64_t dToMs(nanoseconds ns) { return duration_cast<milliseconds>(ns).count(); } |
|
|
|
static int64_t dToUs(nanoseconds ns) { return duration_cast<microseconds>(ns).count(); } |
|
|
|
static int64_t dToS(nanoseconds ns) { return duration_cast<seconds>(ns).count(); } |
|
|
|
static int64_t dToNs(nanoseconds ns) { return ns.count(); } |
|
|
|
|
|
|
|
static inline time_point<T> msToTp(int64_t ms) { |
|
|
|
time_point<T> tp = time_point<T>(milliseconds(ms)); |
|
|
@ -96,6 +96,15 @@ typedef time_point<system_clock> zsystem_tp; |
|
|
|
typedef time_point<steady_clock> zsteady_tp; |
|
|
|
|
|
|
|
static inline int64_t zsys_get_ticket() { return zsystem_clock().getms(); } |
|
|
|
// static inline int64_t zsys_get_local_clock() {
|
|
|
|
// struct timeval tv;
|
|
|
|
// gettimeofday(&tv, NULL);
|
|
|
|
// // 计算毫秒级 Unix 时间戳
|
|
|
|
// // TODO: 修改成时区来自系统
|
|
|
|
// long long timestamp_ms = (long long)tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
|
|
|
// timestamp_ms += 8 * 3600 * 1000; // 转换为北京时间(UTC+8)
|
|
|
|
// return timestamp_ms;
|
|
|
|
// }
|
|
|
|
static inline int64_t zsys_haspassedms(int64_t old) { return zsystem_clock().elapsedTimeMs(old); } |
|
|
|
|
|
|
|
}; // namespace core
|
|
|
|