Skip to content

Conversation

@perpil
Copy link
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
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
Owner

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

@squidfunk
Copy link
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
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
Owner

Thanks!

@squidfunk squidfunk merged commit a08809a into squidfunk:master Nov 19, 2024
4 checks passed
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