From 2b904d4ff7556c205a7e114f062f43f691a147cc Mon Sep 17 00:00:00 2001 From: Timon de Groot Date: Thu, 7 Nov 2024 07:57:32 +0100 Subject: [PATCH] ext/updated_at: Replace Zulu time marker at end of datetime string Sometimes a git log result can return times ending with Z instead of +00:00. The Zulu time marker can be replaced with 00:00 to make it parseable by Python --- hypernode/sphinx/extensions/updated_at.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hypernode/sphinx/extensions/updated_at.py b/hypernode/sphinx/extensions/updated_at.py index 024c633f..978889a8 100644 --- a/hypernode/sphinx/extensions/updated_at.py +++ b/hypernode/sphinx/extensions/updated_at.py @@ -1,4 +1,5 @@ import os.path +import re from datetime import datetime from pathlib import Path from typing import TYPE_CHECKING @@ -37,11 +38,13 @@ def execute(self, app: "Sphinx", pagename: str, templatename, context, doctree): ) if created: + created = re.sub(r"Z$", "+00:00", created) context["created_at"] = datetime.fromisoformat(created).strftime( app.config.created_at_fmt ) if updated: + updated = re.sub(r"Z$", "+00:00", updated) context["updated_at"] = datetime.fromisoformat(updated).strftime( app.config.updated_at_fmt )