fix(cron): accept bare duration units like 'hour' in schedule parsing

This commit is contained in:
salch-cred
2026-08-29 14:00:13 +05:30
committed by Teknium
parent 105b8650ef
commit 1d13fe70b9
2 changed files with 4 additions and 2 deletions

View File

@@ -0,0 +1 @@
salch-cred

View File

@@ -782,13 +782,14 @@ def parse_duration(s: str) -> int:
"30m" → 30
"2h" → 120
"1d" → 1440
"hour" → 60 (bare unit, no leading number)
"""
s = s.strip().lower()
match = re.match(r'^(\d+)\s*(m|min|mins|minute|minutes|h|hr|hrs|hour|hours|d|day|days)$', s)
match = re.match(r'^(\d*)\s*(m|min|mins|minute|minutes|h|hr|hrs|hour|hours|d|day|days)$', s)
if not match:
raise ValueError(f"Invalid duration: '{s}'. Use format like '30m', '2h', or '1d'")
value = int(match.group(1))
value = int(match.group(1)) if match.group(1) else 1
unit = match.group(2)[0] # First char: m, h, or d
multipliers = {'m': 1, 'h': 60, 'd': 1440}