fix(cron): accept bare duration units like 'hour' in schedule parsing
This commit is contained in:
1
contributors/emails/salch-cred@users.noreply.github.com
Normal file
1
contributors/emails/salch-cred@users.noreply.github.com
Normal file
@@ -0,0 +1 @@
|
||||
salch-cred
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user