From 242ccac983acc65ea7a11d3213bb893596014cca Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 1 Dec 2018 17:13:04 +0800 Subject: [PATCH] add GetDaySeconds --- a8/sysutils.cc | 6 ++++++ a8/sysutils.h | 2 ++ a8/timer.cc | 5 ++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/a8/sysutils.cc b/a8/sysutils.cc index c1ed487..9f8cf19 100644 --- a/a8/sysutils.cc +++ b/a8/sysutils.cc @@ -173,6 +173,12 @@ namespace a8 return std::string(buff); } + time_t GetDaySeconds(time_t time_val, int incdays) + { + int g_time_zone = 8; + return time_t((time_val + g_time_zone * 3600)/3600/24 + incdays) * 3600 * 24 - 3600 * g_time_zone; + } + long long MakeInt64(int low32, int high32) { return low32 + ((long long)high32 << 32); diff --git a/a8/sysutils.h b/a8/sysutils.h index 3182bfa..834628f 100644 --- a/a8/sysutils.h +++ b/a8/sysutils.h @@ -63,7 +63,9 @@ namespace a8 bool MkDir(const std::string& path); void ForceCreateDir(const std::string& path); std::string GetIpAddress(unsigned long ip_saddr); + std::string FormatDateTime(time_t time_val); + time_t GetDaySeconds(time_t time_val, int incdays = 0); long long MakeInt64(int low32, int high32); int Low32(long long int64_val); diff --git a/a8/timer.cc b/a8/timer.cc index 73c00fd..232369a 100644 --- a/a8/timer.cc +++ b/a8/timer.cc @@ -2,6 +2,7 @@ #include +#if 0 const int g_time_zone = 8; // 默认东八区 static time_t GetDaySeconds(time_t time, int incdays = 0) @@ -9,6 +10,8 @@ static time_t GetDaySeconds(time_t time, int incdays = 0) return time_t((time + g_time_zone * 3600)/3600/24 + incdays) * 3600 * 24 - 3600 * g_time_zone; } +#endif + #define CONFIG_BASE_SMALL 0 #define TVN_BITS (CONFIG_BASE_SMALL ? 4 : 6) #define TVR_BITS (CONFIG_BASE_SMALL ? 6 : 8) @@ -202,7 +205,7 @@ namespace a8 timer->milli_seconds = milli_seconds; if (timer->timer_type == 2) { long long tick = a8::XGetTickCount(); - long long today_passed_seconds = time(nullptr) - GetDaySeconds(time(nullptr)); + long long today_passed_seconds = time(nullptr) - a8::GetDaySeconds(time(nullptr), 0); timer->expires = (tick - today_passed_seconds * 1000) + milli_seconds; if (timer->fixed_timer_execute_times > 0) { if (timer->expires <= tick) { //已过期