Skip to content

Commit

Permalink
Read events fix: events time were read in UTC
Browse files Browse the repository at this point in the history
Now using proper timezone configured
  • Loading branch information
keul committed Jun 13, 2024
1 parent 9084055 commit dc97ff4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ History

- Read events fix: do not set the ``I`` flag for unknown projects
- Read events fix: events were not sorted by start time
- Read events fix: events time were read in UTC. Now using proper timezone configured

0.7.2 (2024-05-01)
------------------
Expand Down
12 changes: 8 additions & 4 deletions haunts/download.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from dateutil import tz
from googleapiclient.discovery import build
from datetime import datetime, timedelta
import click
Expand Down Expand Up @@ -36,16 +37,19 @@ def filter_my_event(events):

def get_events_at(events_service, calendar_id, date):
"""Get all events from a calendar in a specific date."""
start_datetime = datetime.combine(date, datetime.min.time()).isoformat() + "Z"
start_datetime = datetime.combine(date, datetime.min.time())
end_datetime = (
datetime.combine(date, datetime.min.time())
+ timedelta(days=1)
- timedelta(seconds=1)
).isoformat() + "Z"
)
tz_obj = tz.gettz(get("TIMEZONE", "Etc/GMT"))
start_datetime = start_datetime.replace(tzinfo=tz_obj)
end_datetime = end_datetime.replace(tzinfo=tz_obj)
events_result = events_service.list(
calendarId=calendar_id,
timeMin=start_datetime,
timeMax=end_datetime,
timeMin=start_datetime.isoformat(),
timeMax=end_datetime.isoformat(),
singleEvents=True,
orderBy="startTime",
timeZone=get("TIMEZONE", "Etc/GMT"),
Expand Down

0 comments on commit dc97ff4

Please sign in to comment.