From 5b70a0cfcb3a0cd93931115245c73a5e03c303b4 Mon Sep 17 00:00:00 2001 From: squidfunk Date: Thu, 7 Dec 2023 21:46:36 +0100 Subject: [PATCH] Fixe time being dropped from blog post dates --- material/plugins/blog/structure/options.py | 8 ++++++++ src/plugins/blog/structure/options.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/material/plugins/blog/structure/options.py b/material/plugins/blog/structure/options.py index a71c02293..1d66cff30 100644 --- a/material/plugins/blog/structure/options.py +++ b/material/plugins/blog/structure/options.py @@ -62,6 +62,14 @@ class PostDate(BaseConfigOption[DateDict]): # Convert all date values to datetime for key, value in config[key_name].items(): + + # Handle datetime - since datetime is a subclass of date, we need + # to check it first, or we'll loose time - see https://t.ly/-KG9N + if isinstance(value, datetime): + continue + + # Handle date - we set 00:00:00 as the default time, if the author + # only supplied a date, and convert it to datetime if isinstance(value, date): config[key_name][key] = datetime.combine(value, time()) diff --git a/src/plugins/blog/structure/options.py b/src/plugins/blog/structure/options.py index a71c02293..1d66cff30 100644 --- a/src/plugins/blog/structure/options.py +++ b/src/plugins/blog/structure/options.py @@ -62,6 +62,14 @@ class PostDate(BaseConfigOption[DateDict]): # Convert all date values to datetime for key, value in config[key_name].items(): + + # Handle datetime - since datetime is a subclass of date, we need + # to check it first, or we'll loose time - see https://t.ly/-KG9N + if isinstance(value, datetime): + continue + + # Handle date - we set 00:00:00 as the default time, if the author + # only supplied a date, and convert it to datetime if isinstance(value, date): config[key_name][key] = datetime.combine(value, time())