From 157ed18bfd221152ec510a3b0d1d2fc9473f9d2c Mon Sep 17 00:00:00 2001 From: Heckie75 Date: Thu, 12 Dec 2024 13:29:15 +0100 Subject: [PATCH] [script.timers] 4.0.2 --- script.timers/addon.xml | 5 ++++- .../resources/lib/utils/datetime_utils.py | 22 +++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/script.timers/addon.xml b/script.timers/addon.xml index d25be1db8..5d7eceda8 100644 --- a/script.timers/addon.xml +++ b/script.timers/addon.xml @@ -1,5 +1,5 @@ - + @@ -66,6 +66,9 @@ https://github.com/Heckie75/kodi-addon-timers https://github.com/Heckie75/kodi-addon-timers +v4.0.2 (2024-12-12) +* Bugfix: Fix exception when settings timer in EPG with program that runs over midnight + v4.0.1 (2024-12-08) - Addded translations for French (provided by Skypichat-kodi and Gemini) - Bugfix: Prevent exception when turning off timers by deselecting all days of week diff --git a/script.timers/resources/lib/utils/datetime_utils.py b/script.timers/resources/lib/utils/datetime_utils.py index d417ac936..f117776ca 100644 --- a/script.timers/resources/lib/utils/datetime_utils.py +++ b/script.timers/resources/lib/utils/datetime_utils.py @@ -1,4 +1,5 @@ import locale +import re import time from datetime import datetime, timedelta @@ -160,16 +161,23 @@ def parse_time(s_time: str, i_day=0) -> timedelta: if s_time == "": s_time = DEFAULT_TIME - if s_time.lower().endswith(" am") or s_time.lower().endswith(" pm"): - t_time = time.strptime(s_time, "%I:%M %p") + m = re.match("^(\d{1,2}):(\d{1,2})( am)?( pm)?$", s_time.lower()) + if not m: + return None - else: - t_time = time.strptime(s_time, "%H:%M") + tm_hour = int(m.groups()[0]) + if m.groups()[2] and tm_hour >= 12: # am: + tm_hour -= 12 + elif m.groups()[3] and tm_hour < 12: # pm + tm_hour += 12 + + tm_min = int(m.groups()[1]) + tm_day = i_day + tm_hour // 24 return timedelta( - days=i_day, - hours=t_time.tm_hour, - minutes=t_time.tm_min) + days=tm_day, + hours=tm_hour % 24, + minutes=tm_min) def datetime_diff(t1: datetime, t2: datetime) -> int: