1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-24 04:05:39 +01:00

dash.parse_dates: support everything between miliseconds and nanoseconds

This commit is contained in:
Johan Andersson 2021-06-30 12:45:06 +02:00
parent 09843d632a
commit c66590c807
2 changed files with 6 additions and 1 deletions

View File

@ -299,7 +299,7 @@ def parse_duration(duration):
def parse_dates(date_str):
match = re.search(r"(.*:.*)\.(\d{9})Z", date_str)
match = re.search(r"(.*:.*)\.(\d{5,9})Z", date_str)
if match:
date_str = f"{match.group(1)}.{int(int(match.group(2))/1000)}Z" # Need to translate nanoseconds to milliseconds
date_patterns = ["%Y-%m-%dT%H:%M:%S.%fZ", "%Y-%m-%dT%H:%M:%S", "%Y-%m-%dT%H:%M:%SZ"]

View File

@ -69,6 +69,11 @@ def test_parse_duration():
def test_parse_date():
assert isinstance(parse_dates("2021-05-10T06:00:11.451554796Z"), datetime.datetime)
assert isinstance(parse_dates("2021-05-10T06:00:11.45155479Z"), datetime.datetime)
assert isinstance(parse_dates("2021-05-10T06:00:11.4515547Z"), datetime.datetime)
assert isinstance(parse_dates("2021-05-10T06:00:11.451554Z"), datetime.datetime)
assert isinstance(parse_dates("2021-05-10T06:00:11.45155Z"), datetime.datetime)
assert isinstance(parse_dates("2021-05-10T06:00:11.4515Z"), datetime.datetime)
assert isinstance(parse_dates("2021-05-10T06:00:11.45Z"), datetime.datetime)
assert isinstance(parse_dates("2021-05-10T06:00:11Z"), datetime.datetime)
assert isinstance(parse_dates("2021-05-10T06:00:11"), datetime.datetime)