1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-11-23 23:21:00 +01:00

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
This commit is contained in:
perpil 2024-11-19 04:39:37 -08:00 committed by GitHub
parent d4f0b6693f
commit a08809a0f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 6 deletions

View File

@ -18,7 +18,7 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE. # IN THE SOFTWARE.
from datetime import date, datetime, time from datetime import date, datetime, time, timezone
from mkdocs.config.base import BaseConfigOption, Config, ValidationError from mkdocs.config.base import BaseConfigOption, Config, ValidationError
from typing import Dict from typing import Dict
@ -69,9 +69,9 @@ class PostDate(BaseConfigOption[DateDict]):
continue continue
# Handle date - we set 00:00:00 as the default time, if the author # Handle date - we set 00:00:00 as the default time, if the author
# only supplied a date, and convert it to datetime # only supplied a date, and convert it to datetime in UTC
if isinstance(value, date): if isinstance(value, date):
config[key_name][key] = datetime.combine(value, time()) config[key_name][key] = datetime.combine(value, time()).replace(tzinfo=timezone.utc)
# Initialize date dictionary # Initialize date dictionary
config[key_name] = DateDict(config[key_name]) config[key_name] = DateDict(config[key_name])

View File

@ -18,7 +18,7 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE. # IN THE SOFTWARE.
from datetime import date, datetime, time from datetime import date, datetime, time, timezone
from mkdocs.config.base import BaseConfigOption, Config, ValidationError from mkdocs.config.base import BaseConfigOption, Config, ValidationError
from typing import Dict from typing import Dict
@ -69,9 +69,9 @@ class PostDate(BaseConfigOption[DateDict]):
continue continue
# Handle date - we set 00:00:00 as the default time, if the author # Handle date - we set 00:00:00 as the default time, if the author
# only supplied a date, and convert it to datetime # only supplied a date, and convert it to datetime in UTC
if isinstance(value, date): if isinstance(value, date):
config[key_name][key] = datetime.combine(value, time()) config[key_name][key] = datetime.combine(value, time()).replace(tzinfo=timezone.utc)
# Initialize date dictionary # Initialize date dictionary
config[key_name] = DateDict(config[key_name]) config[key_name] = DateDict(config[key_name])