[utils] Improve parse_duration
This commit is contained in:
parent
9c4c233b84
commit
ca7b3246b6
2 changed files with 6 additions and 1 deletions
|
@ -1332,8 +1332,10 @@ def parse_duration(s):
|
|||
if s is None:
|
||||
return None
|
||||
|
||||
s = s.strip()
|
||||
|
||||
m = re.match(
|
||||
r'(?:(?:(?P<hours>[0-9]+)[:h])?(?P<mins>[0-9]+)[:m])?(?P<secs>[0-9]+)s?(?::[0-9]+)?(?P<ms>\.[0-9]+)?$', s)
|
||||
r'(?:(?:(?P<hours>[0-9]+)\s*(?:[:h]|hours?)\s*)?(?P<mins>[0-9]+)\s*(?:[:m]|mins?|minutes?)\s*)?(?P<secs>[0-9]+)(?P<ms>\.[0-9]+)?\s*(?:s|secs?|seconds?)?$', s)
|
||||
if not m:
|
||||
return None
|
||||
res = int(m.group('secs'))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue