From eee4934efdf21f6d3bc576afd02a63cf96485299 Mon Sep 17 00:00:00 2001 From: perpil <97474956+perpil@users.noreply.github.com> Date: Wed, 20 Nov 2024 09:22:48 -0800 Subject: [PATCH] Fixed blog plugin crashing on missing timezone (regression) (#7730) * Default timezone to UTC for blog plugin created date Fix for https://github.com/squidfunk/mkdocs-material/issues/7725 * Fix variable name * Run build --- material/plugins/blog/structure/options.py | 6 +++++- src/plugins/blog/structure/options.py | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/material/plugins/blog/structure/options.py b/material/plugins/blog/structure/options.py index a7bab08fe..1dde16ea8 100644 --- a/material/plugins/blog/structure/options.py +++ b/material/plugins/blog/structure/options.py @@ -66,7 +66,11 @@ class PostDate(BaseConfigOption[DateDict]): # Handle datetime - since datetime is a subclass of date, we need # to check it first, or we lose the time - see https://t.ly/-KG9N if isinstance(value, datetime): - continue + # Set timezone to UTC if not set + if value.tzinfo is None: + config[key_name][key] = value.replace(tzinfo=timezone.utc) + continue; + # Handle date - we set 00:00:00 as the default time, if the author # only supplied a date, and convert it to datetime in UTC diff --git a/src/plugins/blog/structure/options.py b/src/plugins/blog/structure/options.py index a7bab08fe..1dde16ea8 100644 --- a/src/plugins/blog/structure/options.py +++ b/src/plugins/blog/structure/options.py @@ -66,7 +66,11 @@ class PostDate(BaseConfigOption[DateDict]): # Handle datetime - since datetime is a subclass of date, we need # to check it first, or we lose the time - see https://t.ly/-KG9N if isinstance(value, datetime): - continue + # Set timezone to UTC if not set + if value.tzinfo is None: + config[key_name][key] = value.replace(tzinfo=timezone.utc) + continue; + # Handle date - we set 00:00:00 as the default time, if the author # only supplied a date, and convert it to datetime in UTC