添加星期任务成功

This commit is contained in:
zogodo
2020-03-08 17:48:16 +08:00
parent 6ba7c92e80
commit a648ae061f

View File

@@ -8,7 +8,7 @@
pTimedTask task_top = NULL;
int task_count = 0;
bool AddTask(pTimedTask task)
bool AddTaskSingle(pTimedTask task)
{
task_count++;
if (task_top == NULL)
@@ -42,6 +42,24 @@ bool AddTask(pTimedTask task)
return false;
}
bool AddTaskWeek(pTimedTask task)
{
int day_sec = 86400;
time_t now = time(NULL);
int today_weekday = (now / day_sec + 3) % 7 + 1; //1970-01-01 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int next_day = task->weekday - today_weekday;
next_day = next_day > 0 ? next_day : next_day + 7;
task->prs_time = (now - now % day_sec) + (next_day * day_sec) + task->prs_time % day_sec;
return AddTaskSingle(task);
}
bool AddTask(pTimedTask task)
{
if (task->weekday == 0) return AddTaskSingle(task);
return AddTaskWeek(task);
}
bool DelFirstTask()
{
if (task_top)