File size: 268 Bytes
b5d1dbc
 
 
 
 
 
 
1
2
3
4
5
6
7
8
def parse_duration(text):
    """Parse durations like '1h30m', '45s', '2h5s' or '90m' into total seconds."""
    import re
    total = 0
    for value, unit in re.findall(r"(\d+)([hm])", text):
        total += int(value) * {"h": 3600, "m": 60}[unit]
    return total