Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Commit

Permalink
Ensure timezone is applied to every datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
johanohly committed Feb 9, 2024
1 parent 172440d commit 63f2589
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions custom_components/bedste_lectio/sensor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Sensor platforms for BedsteLectio."""
from __future__ import annotations
from datetime import datetime
from datetime import datetime, timedelta
from zoneinfo import ZoneInfo
from dateutil import parser

Expand Down Expand Up @@ -45,7 +45,7 @@ def get_next_room(entries: list[dict[str, str]]) -> dict[str, str]:
rooms = []
for entry in entries:
date = parser.parse(entry["tidspunkt"].split(" til")[0], fuzzy=True).replace(tzinfo=ZoneInfo("Europe/Copenhagen"))
if date < datetime.now(tz=ZoneInfo("Europe/Copenhagen")):
if date < datetime.now().astimezone(ZoneInfo("Europe/Copenhagen")):
continue

rooms.append({
Expand Down Expand Up @@ -84,6 +84,6 @@ def extra_state_attributes(self) -> dict[str, any]:
entries = self.coordinator.data.get("skema")
data = get_next_room(entries)
data.update({
"last_update": datetime.now(tz=ZoneInfo("Europe/Copenhagen")),
"last_update": datetime.now().astimezone(ZoneInfo("Europe/Copenhagen")),
})
return data

0 comments on commit 63f2589

Please sign in to comment.