From cae334d94eb08d915e486a84d0664e60f6c23ccd Mon Sep 17 00:00:00 2001 From: sansan <77180927+sansan0@users.noreply.github.com> Date: Mon, 13 Oct 2025 14:59:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E7=AA=97=E5=8F=A3=E5=88=A4=E6=96=AD=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index abcec14..be04f80 100644 --- a/main.py +++ b/main.py @@ -380,7 +380,35 @@ class PushRecordManager: """检查当前时间是否在指定时间范围内""" now = get_beijing_time() current_time = now.strftime("%H:%M") - return start_time <= current_time <= end_time + + def normalize_time(time_str: str) -> str: + """将时间字符串标准化为 HH:MM 格式""" + try: + parts = time_str.strip().split(":") + if len(parts) != 2: + raise ValueError(f"时间格式错误: {time_str}") + + hour = int(parts[0]) + minute = int(parts[1]) + + if not (0 <= hour <= 23 and 0 <= minute <= 59): + raise ValueError(f"时间范围错误: {time_str}") + + return f"{hour:02d}:{minute:02d}" + except Exception as e: + print(f"时间格式化错误 '{time_str}': {e}") + return time_str + + normalized_start = normalize_time(start_time) + normalized_end = normalize_time(end_time) + normalized_current = normalize_time(current_time) + + result = normalized_start <= normalized_current <= normalized_end + + if not result: + print(f"时间窗口判断:当前 {normalized_current},窗口 {normalized_start}-{normalized_end}") + + return result # === 数据获取 ===