Skip to content

Commit a08809a

Browse files
authored
Fixed blog plugin crashing on dates with timezones (#7708)
* Normalize datetime values to UTC in blog plugin Fixes #7705 Normalize datetime values to UTC in blog plugin to handle offset-naive and offset-aware datetimes correctly. * Import `timezone` from `datetime` in `material/plugins/blog/structure/options.py`. * Modify `pre_validation` method to set `tzinfo=timezone.utc` for datetime values. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/squidfunk/mkdocs-material/issues/7705?shareId=XXXX-XXXX-XXXX-XXXX). * Normalize datetime values to UTC in blog plugin Fixes #7705 + Move changes to src directory
1 parent d4f0b66 commit a08809a

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

material/plugins/blog/structure/options.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
1919
# IN THE SOFTWARE.
2020

21-
from datetime import date, datetime, time
21+
from datetime import date, datetime, time, timezone
2222
from mkdocs.config.base import BaseConfigOption, Config, ValidationError
2323
from typing import Dict
2424

@@ -69,9 +69,9 @@ def pre_validation(self, config: Config, key_name: str):
6969
continue
7070

7171
# Handle date - we set 00:00:00 as the default time, if the author
72-
# only supplied a date, and convert it to datetime
72+
# only supplied a date, and convert it to datetime in UTC
7373
if isinstance(value, date):
74-
config[key_name][key] = datetime.combine(value, time())
74+
config[key_name][key] = datetime.combine(value, time()).replace(tzinfo=timezone.utc)
7575

7676
# Initialize date dictionary
7777
config[key_name] = DateDict(config[key_name])

src/plugins/blog/structure/options.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
1919
# IN THE SOFTWARE.
2020

21-
from datetime import date, datetime, time
21+
from datetime import date, datetime, time, timezone
2222
from mkdocs.config.base import BaseConfigOption, Config, ValidationError
2323
from typing import Dict
2424

@@ -69,9 +69,9 @@ def pre_validation(self, config: Config, key_name: str):
6969
continue
7070

7171
# Handle date - we set 00:00:00 as the default time, if the author
72-
# only supplied a date, and convert it to datetime
72+
# only supplied a date, and convert it to datetime in UTC
7373
if isinstance(value, date):
74-
config[key_name][key] = datetime.combine(value, time())
74+
config[key_name][key] = datetime.combine(value, time()).replace(tzinfo=timezone.utc)
7575

7676
# Initialize date dictionary
7777
config[key_name] = DateDict(config[key_name])

0 commit comments

Comments
 (0)