From 30b36b68ddf95cdfbef3cf5ce67f1363cedac6fb Mon Sep 17 00:00:00 2001 From: KenanZhu <3471685733@qq.com> Date: Thu, 19 Mar 2026 11:56:44 +0800 Subject: [PATCH] =?UTF-8?q?refactor(ALTimerTaskManageWidget):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E9=87=8D=E5=A4=8D=E4=BB=BB=E5=8A=A1=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复 onRepeatTimerTaskIs 方法中日期循环索引错误,使用 %7 正确处理跨周星期计算 - 新增 OUTDATED 状态的专属处理逻辑,补全过期任务的历史记录 - 添加函数返回值并统一枚举比较方式为 ==,提高代码一致性 --- src/gui/ALTimerTaskManageWidget.py | 39 +++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/gui/ALTimerTaskManageWidget.py b/src/gui/ALTimerTaskManageWidget.py index 3fa2b65..de53606 100644 --- a/src/gui/ALTimerTaskManageWidget.py +++ b/src/gui/ALTimerTaskManageWidget.py @@ -575,17 +575,37 @@ class ALTimerTaskManageWidget(QWidget, Ui_ALTimerTaskManageWidget): timer_task: dict ) -> dict: + # only these status are valid + valid_statuses = {ALTimerTaskStatus.EXECUTED, ALTimerTaskStatus.ERROR, + ALTimerTaskStatus.OUTDATED} + if status not in valid_statuses: + return timer_task if "history" not in timer_task: timer_task["history"] = [] - executed_time = datetime.now() - duration = (executed_time - timer_task["execute_time"]).total_seconds() - timer_task["history"].append({ - "execute_time": timer_task["execute_time"].strftime("%Y-%m-%d %H:%M:%S"), - "executed_time": executed_time.strftime("%Y-%m-%d %H:%M:%S"), - "result": status, - "duration": duration if status is ALTimerTaskStatus.EXECUTED else 0, - "uuid": timer_task["task_uuid"] - }) + if status != ALTimerTaskStatus.OUTDATED: + executed_time = datetime.now() + duration = (executed_time - timer_task["execute_time"]).total_seconds() + timer_task["history"].append({ + "execute_time": timer_task["execute_time"].strftime("%Y-%m-%d %H:%M:%S"), + "executed_time": executed_time.strftime("%Y-%m-%d %H:%M:%S"), + "result": status, + "duration": duration, + "uuid": timer_task["task_uuid"] + }) + else: + current_time = datetime.now() + execute_time = timer_task["execute_time"] + execute_weekday = execute_time.weekday() + delta_days = (current_time - execute_time).days + for i in range(delta_days): + if (execute_weekday + i)%7 in timer_task["repeat_days"]: + timer_task["history"].append({ + "execute_time": (execute_time + timedelta(days=i)).strftime("%Y-%m-%d %H:%M:%S"), + "executed_time": (execute_time + timedelta(days=i)).strftime("%Y-%m-%d %H:%M:%S"), + "result": status, + "duration": 0, + "uuid": timer_task["task_uuid"] + }) next_time = TimerUtils.calculateNextRepeatTime( timer_task["repeat_days"], timer_task["repeat_hour"], @@ -598,6 +618,7 @@ class ALTimerTaskManageWidget(QWidget, Ui_ALTimerTaskManageWidget): timer_task["executed"] = False else: timer_task["status"] = status + return timer_task @Slot(dict) def onTimerTaskIsExecuted(