summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Godwin2022-12-04 07:30:49 -0700
committerAndrew Godwin2022-12-04 07:31:22 -0700
commit864b730164d5830a19eb0fdd93b95d696e08eaf9 (patch)
tree613156f2a0f8ffcc2c60e9a30bb906c812465324
parent7a7907a6df66ea4fb556a1e2c2a991fa60a25d1b (diff)
downloadtakahe-864b730164d5830a19eb0fdd93b95d696e08eaf9.tar.gz
takahe-864b730164d5830a19eb0fdd93b95d696e08eaf9.tar.bz2
takahe-864b730164d5830a19eb0fdd93b95d696e08eaf9.zip
Accept dates with milliseconds in them
-rw-r--r--core/ld.py13
1 files changed, 10 insertions, 3 deletions
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):