21 lines
597 B
Python
21 lines
597 B
Python
import re
|
|
|
|
# Define the time_regex that was missing
|
|
time_regex = re.compile(r'(\d+)([smhd])')
|
|
|
|
def parse_time(time_str):
|
|
"""
|
|
Parse time strings like "4m2s", "1h30m" into seconds.
|
|
|
|
Args:
|
|
time_str: String in format like "4m2s", "1h30m"
|
|
|
|
Returns:
|
|
Integer of total seconds or None if invalid
|
|
"""
|
|
units = {'s': 1, 'm': 60, 'h': 3600, 'd': 86400}
|
|
try:
|
|
total_seconds = sum(int(amount) * units[unit] for amount, unit in time_regex.findall(time_str))
|
|
return total_seconds if total_seconds > 0 else None
|
|
except:
|
|
return None |