1
This commit is contained in:
parent
a0d01a57a5
commit
a7fb25b2f7
@ -209,6 +209,32 @@ namespace a8
|
||||
return time_t((time_val + g_time_zone * 3600)/3600/24 + incdays) * 3600 * 24 - 3600 * g_time_zone;
|
||||
}
|
||||
|
||||
time_t GetMondaySeconds(time_t time_val)
|
||||
{
|
||||
struct tm tm_time = {0};
|
||||
struct tm *ptr = localtime_r(&time_val, &tm_time);
|
||||
if (!ptr) {
|
||||
abort();
|
||||
}
|
||||
|
||||
switch (tm_time.tm_wday) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
return GetDaySeconds(time_val - (3600 * 24 * (tm_time.tm_wday - 1)));
|
||||
break;
|
||||
case 0:
|
||||
return GetDaySeconds(time_val - (3600 * 24 * 6));
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
return time_val;
|
||||
}
|
||||
}
|
||||
|
||||
time_t BetweenDays(time_t time_val1, time_t time_val2)
|
||||
{
|
||||
int g_time_zone = 8;
|
||||
@ -230,6 +256,17 @@ namespace a8
|
||||
#endif
|
||||
}
|
||||
|
||||
time_t GetTimeDaySeconds(const char* time_str)
|
||||
{
|
||||
struct tm stm = {0};
|
||||
char* p = strptime(time_str, "%Y-%m-%d %H:%M:%S", &stm);
|
||||
if (!p) {
|
||||
return -1;
|
||||
}
|
||||
long t = mktime(&stm);
|
||||
return GetDaySeconds(t);
|
||||
}
|
||||
|
||||
long long MakeInt64(int low32, int high32)
|
||||
{
|
||||
return low32 + ((long long)high32 << 32);
|
||||
|
@ -80,8 +80,10 @@ namespace a8
|
||||
std::string TimestampToDateTime(time_t time_val);
|
||||
std::string TimestampToDate(time_t time_val);
|
||||
time_t GetDaySeconds(time_t time_val, int incdays = 0);
|
||||
time_t GetMondaySeconds(time_t time_val);
|
||||
time_t BetweenDays(time_t time_val1, time_t time_val2);
|
||||
time_t GetDateTimeSeconds(const char* datetime_str);
|
||||
time_t GetTimeDaySeconds(const char* time_str);
|
||||
|
||||
long long MakeInt64(int low32, int high32);
|
||||
int Low32(long long int64_val);
|
||||
|
10
a8/timer.cc
10
a8/timer.cc
@ -213,6 +213,16 @@ namespace a8
|
||||
return timer;
|
||||
}
|
||||
|
||||
timer_list* Timer::AddFixedTimerAndAttach(int milli_seconds,
|
||||
a8::XParams param,
|
||||
a8::TimerFunc timer_func,
|
||||
list_head* attach_list)
|
||||
{
|
||||
timer_list *timer = AddFixedTimer(milli_seconds, param, timer_func);
|
||||
list_add_tail(&timer->attach_entry, attach_list);
|
||||
return timer;
|
||||
}
|
||||
|
||||
void Timer::ModifyTimer(timer_list* timer, int milli_seconds)
|
||||
{
|
||||
DetachTimer(timer);
|
||||
|
@ -39,6 +39,10 @@ namespace a8
|
||||
a8::TimerAfterFunc timer_after_func = nullptr);
|
||||
//添加固定时间定时器(每天,每次重启一天里可能会多次调用)
|
||||
timer_list* AddFixedTimer(int milli_seconds, a8::XParams param, a8::TimerFunc timer_func);
|
||||
timer_list* AddFixedTimerAndAttach(int milli_seconds,
|
||||
a8::XParams param,
|
||||
a8::TimerFunc timer_func,
|
||||
list_head* attach_list);
|
||||
//修改定时器参数
|
||||
void ModifyTimer(timer_list* timer, int milli_seconds);
|
||||
//删除定时器
|
||||
|
Loading…
x
Reference in New Issue
Block a user