Skip to content

Normalize datetime values to UTC in blog plugin#7708

Merged
squidfunk merged 2 commits intosquidfunk:masterfrom
perpil:fix-blog-plugin-dates-7705
Nov 19, 2024
Merged

Normalize datetime values to UTC in blog plugin#7708
squidfunk merged 2 commits intosquidfunk:masterfrom
perpil:fix-blog-plugin-dates-7705

Conversation

@perpil
Copy link
Copy Markdown
Contributor

@perpil perpil commented Nov 18, 2024

Fixes #7705

Normalize datetime values to UTC in blog plugin to make the datetime object offset-aware.

  • 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.

Fixes squidfunk#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).
@vedranmiletic
Copy link
Copy Markdown
Contributor

FWIW, in MkDocs itself, a similar issue with timezones mkdocs/mkdocs#3794 was resolved in roughly the same way mkdocs/mkdocs#3795 several months ago.

@squidfunk
Copy link
Copy Markdown
Owner

Thanks for the PR, and @vedranmiletic for linking the related issue. Looks sensible!

@squidfunk
Copy link
Copy Markdown
Owner

Ah, one problem: please make the changes in the src folder as well. The material folder is built from it, as mentioned in our theme development guide:

Warning

Never make any changes in the material directory, as the contents of this directory are automatically generated from the src directory and will be overwritten when the theme is built.

@perpil
Copy link
Copy Markdown
Contributor Author

perpil commented Nov 18, 2024

Ah! I'd forgotten since last time. I've updated the PR to only modify the src.

@squidfunk
Copy link
Copy Markdown
Owner

Thanks!

@squidfunk squidfunk merged commit a08809a into squidfunk:master Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blog plugin failing with TypeError: can't compare offset-naive and offset-aware datetimes

3 participants