From a648ae061f98814bb9f882c2e6215a953f21ac8a Mon Sep 17 00:00:00 2001 From: zogodo <742782908@qq.com> Date: Sun, 8 Mar 2020 17:48:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=98=9F=E6=9C=9F=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TC1/timed_task/timed_task.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/TC1/timed_task/timed_task.c b/TC1/timed_task/timed_task.c index 1171b96..1b6dad0 100644 --- a/TC1/timed_task/timed_task.c +++ b/TC1/timed_task/timed_task.c @@ -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 ÐÇÆÚÎå + 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)