Skip to content

Normalize datetime values to UTC in blog plugin #7708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions material/plugins/blog/structure/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# 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 typing import Dict

Expand Down Expand Up @@ -69,9 +69,9 @@ def pre_validation(self, config: Config, key_name: str):
continue

# 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):
config[key_name][key] = datetime.combine(value, time())
config[key_name][key] = datetime.combine(value, time()).replace(tzinfo=timezone.utc)

# Initialize date dictionary
config[key_name] = DateDict(config[key_name])
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/blog/structure/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# 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 typing import Dict

Expand Down Expand Up @@ -69,9 +69,9 @@ def pre_validation(self, config: Config, key_name: str):
continue

# 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):
config[key_name][key] = datetime.combine(value, time())
config[key_name][key] = datetime.combine(value, time()).replace(tzinfo=timezone.utc)

# Initialize date dictionary
config[key_name] = DateDict(config[key_name])
Expand Down