check_systemd_timer: fix time detection

This commit is contained in:
Cyberes 2024-04-01 13:45:08 -06:00
parent 7c8dbd9099
commit 5fab8adf54
2 changed files with 3 additions and 3 deletions

View File

@ -40,13 +40,13 @@ def get_next_elapse(timer_name):
if parts.group(4): if parts.group(4):
time_left = parse_systemctl_time_delta(parts.group(4)) time_left = parse_systemctl_time_delta(parts.group(4))
if isinstance(time_left, humanfriendly.InvalidTimespan): if isinstance(time_left, humanfriendly.InvalidTimespan):
return None, humanfriendly.InvalidTimespan return None, Exception(f'Invalid Timespan: "{parts.group(4)}"')
time_passed = 'n/a' time_passed = 'n/a'
if parts.group(9): if parts.group(9):
time_passed = parse_systemctl_time_delta(parts.group(9)) time_passed = parse_systemctl_time_delta(parts.group(9))
if isinstance(time_passed, humanfriendly.InvalidTimespan): if isinstance(time_passed, humanfriendly.InvalidTimespan):
return None, humanfriendly.InvalidTimespan return None, Exception(f'Invalid Timespan: "{parts.group(9)}"')
timer_info = { timer_info = {
'next': datetime_object, 'next': datetime_object,

View File

@ -13,7 +13,7 @@ def parse_systemctl_time_delta(time_str: str):
spans = [] spans = []
for part in re.findall(SYSTEMCTL_TIMESPAN_RE, time_str): for part in re.findall(SYSTEMCTL_TIMESPAN_RE, time_str):
delta = part[0] delta = part[0]
if 'months' in delta: if 'month' in delta:
# humanfriendly does not support "months" so we convert it to weeks # humanfriendly does not support "months" so we convert it to weeks
num = int(delta.split(' ')[0]) num = int(delta.split(' ')[0])
delta = f'{num * 4} weeks' delta = f'{num * 4} weeks'