I have an issue with the query of getting all-day type events on a day from Microsoft calendar using O365 library. Actually, I'm going to fetch the events on a specific day by a query, and the problem is I get an extra all-day event from the previous day as well!
My ms-calendar timezone is set to Istanbul; subsequently, the query's start date and end date are also in the Istanbul timezone via an aware-datetime.
Here's what I've done so far:
...
start_date = pytz.timezone("Europe/Istanbul").localize(datetime(2022, 9, 18))
end_date = pytz.timezone("Europe/Istanbul").localize(datetime(2022, 9, 19))
q = calendar.new_query('start').greater_equal(start_date)
q.chain('and').on_attribute('end').less(end_date)
events = calendar.get_events(query=q, include_recurring=True)
pprint(
[
(
g.to_api_data()["subject"],
g.to_api_data()["start"],
g.to_api_data()["end"]
) for g in events])
Out:
[('dummy 1',
{'dateTime': '2022-09-17T03:00:00', 'timeZone': 'Turkey Standard Time'},
{'dateTime': '2022-09-18T03:00:00', 'timeZone': 'Turkey Standard Time'}),
('event 2',
{'dateTime': '2022-09-18T00:00:00', 'timeZone': 'Turkey Standard Time'},
{'dateTime': '2022-09-18T00:30:00', 'timeZone': 'Turkey Standard Time'}),
('dummy 2',
{'dateTime': '2022-09-18T03:00:00', 'timeZone': 'Turkey Standard Time'},
{'dateTime': '2022-09-19T03:00:00', 'timeZone': 'Turkey Standard Time'}),
('event 4',
{'dateTime': '2022-09-18T23:30:00', 'timeZone': 'Turkey Standard Time'},
{'dateTime': '2022-09-19T00:00:00', 'timeZone': 'Turkey Standard Time'})]
As you can see in the below screenshot, my expectation would be getting dummy 2
, event 2
, and event 4
, but I'm also getting dummy 1
as well which is into the previous day!
[UPDATE]:
Apparently, the cause of this problem is that +3 hours (Turkey Time) have been added to the all-day events' time but not to the normal events.
I bypassed this issue as follows — adding 1 second forward and backward:
Out:
Moreover, about the added extra +3 hours I would have to say that, that was not the main problem as it doesn't matter to the query and it's just the representation of the datetime in which I fixed that by myself and I'm going go to send a PR to the O365.