Use the local timezone when parsing Todoist due dates (#45994)
parent
62e49e545b
commit
bf64421be9
|
@ -226,15 +226,14 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
)
|
||||
|
||||
|
||||
def _parse_due_date(data: dict) -> datetime:
|
||||
def _parse_due_date(data: dict, gmt_string) -> datetime:
|
||||
"""Parse the due date dict into a datetime object."""
|
||||
# Add time information to date only strings.
|
||||
if len(data["date"]) == 10:
|
||||
data["date"] += "T00:00:00"
|
||||
# If there is no timezone provided, use UTC.
|
||||
if data["timezone"] is None:
|
||||
data["date"] += "Z"
|
||||
return dt.parse_datetime(data["date"])
|
||||
if dt.parse_datetime(data["date"]).tzinfo is None:
|
||||
data["date"] += gmt_string
|
||||
return dt.as_utc(dt.parse_datetime(data["date"]))
|
||||
|
||||
|
||||
class TodoistProjectDevice(CalendarEventDevice):
|
||||
|
@ -407,7 +406,9 @@ class TodoistProjectData:
|
|||
# Generally speaking, that means right now.
|
||||
task[START] = dt.utcnow()
|
||||
if data[DUE] is not None:
|
||||
task[END] = _parse_due_date(data[DUE])
|
||||
task[END] = _parse_due_date(
|
||||
data[DUE], self._api.state["user"]["tz_info"]["gmt_string"]
|
||||
)
|
||||
|
||||
if self._due_date_days is not None and (
|
||||
task[END] > dt.utcnow() + self._due_date_days
|
||||
|
@ -529,9 +530,19 @@ class TodoistProjectData:
|
|||
for task in project_task_data:
|
||||
if task["due"] is None:
|
||||
continue
|
||||
due_date = _parse_due_date(task["due"])
|
||||
due_date = _parse_due_date(
|
||||
task["due"], self._api.state["user"]["tz_info"]["gmt_string"]
|
||||
)
|
||||
midnight = dt.as_utc(
|
||||
dt.parse_datetime(
|
||||
due_date.strftime("%Y-%m-%d")
|
||||
+ "T00:00:00"
|
||||
+ self._api.state["user"]["tz_info"]["gmt_string"]
|
||||
)
|
||||
)
|
||||
|
||||
if start_date < due_date < end_date:
|
||||
if due_date.hour == 0 and due_date.minute == 0:
|
||||
if due_date == midnight:
|
||||
# If the due date has no time data, return just the date so that it
|
||||
# will render correctly as an all day event on a calendar.
|
||||
due_date_value = due_date.strftime("%Y-%m-%d")
|
||||
|
|
Loading…
Reference in New Issue