From 864b730164d5830a19eb0fdd93b95d696e08eaf9 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sun, 4 Dec 2022 07:30:49 -0700 Subject: Accept dates with milliseconds in them --- core/ld.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/ld.py b/core/ld.py index 1d79abf..f70642a 100644 --- a/core/ld.py +++ b/core/ld.py @@ -367,6 +367,7 @@ schemas = { } DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ" +DATETIME_MS_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ" def builtin_document_loader(url: str, options={}): @@ -440,9 +441,15 @@ def format_ld_date(value: datetime.datetime) -> str: def parse_ld_date(value: Optional[str]) -> Optional[datetime.datetime]: if value is None: return None - return datetime.datetime.strptime(value, DATETIME_FORMAT).replace( - tzinfo=datetime.timezone.utc - ) + try: + return datetime.datetime.strptime(value, DATETIME_FORMAT).replace( + tzinfo=datetime.timezone.utc + ) + except ValueError: + return datetime.datetime.strptime(value, DATETIME_MS_FORMAT).replace( + tzinfo=datetime.timezone.utc, + microsecond=0, + ) def media_type_from_filename(filename): -- cgit v1.2.3