1
0

Import parse util

This commit is contained in:
Jon Michael Aanes 2024-11-08 21:42:33 +01:00
parent 9906d34314
commit a5c36d7acb
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA

View File

@ -22,7 +22,7 @@ FORMAT_DATE_HEADER = '%a, %d %b %Y %H:%M:%S GMT'
def parse_duration(text: str) -> datetime.timedelta: def parse_duration(text: str) -> datetime.timedelta:
(num_str, unit_str) = text.split(' ') (num_str, unit_str) = text.split(' ')
num = int(num_str) num = float(num_str)
unit = DATETIME_UNITS[unit_str] unit = DATETIME_UNITS[unit_str]
return unit * num return unit * num
@ -78,5 +78,7 @@ def parse_date(text: str) -> datetime.date:
return dt.date() return dt.date()
if dt := try_parse(text, '%B %d, %Y'): if dt := try_parse(text, '%B %d, %Y'):
return dt.date() return dt.date()
if dt := try_parse(text, '%b %d'):
return dt.date()
msg = 'Unknown format: ' + text msg = 'Unknown format: ' + text
raise RuntimeError(msg) raise RuntimeError(msg)