python-o365
python-o365 copied to clipboard
problem with the query of getting all-day type events on a day
I have an issue with the query of getting all-day type events on a day. 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.
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!
I'm also suspicious about the extra +3 hours for all-day events only!

Hi @janscas
Could you please look into this issue?
I bypassed this issue as follows — adding 1 second forward and backward:
from datetime import timedelta
...
start_date = pytz.timezone("Europe/Istanbul").localize(datetime(2022, 9, 18))
end_date = pytz.timezone("Europe/Istanbul").localize(datetime(2022, 9, 19))
start_date += timedelta(seconds=1)
end_date += timedelta(seconds=-1)
...
Out:
[('event 2',
{'dateTime': '2022-09-18T00:00:00+03:00', 'timeZone': 'Europe/Istanbul'},
{'dateTime': '2022-09-18T00:30:00+03:00', 'timeZone': 'Europe/Istanbul'}),
('dummy 2',
{'dateTime': '2022-09-18T00:00:00+03:00', 'timeZone': 'Europe/Istanbul'},
{'dateTime': '2022-09-19T00:00:00+03:00', 'timeZone': 'Europe/Istanbul'}),
('event 4',
{'dateTime': '2022-09-18T23:30:00+03:00', 'timeZone': 'Europe/Istanbul'},
{'dateTime': '2022-09-19T00:00:00+03:00', 'timeZone': 'Europe/Istanbul'})]
Moreover, about the added extra +3 hours I sent a PR (#843 ).
Can't look into that.
This library was build around datetimes that are aware of the timezone. So it's always getting from a timezone and converting timezones. Also when sending data, sends UTC. That was a wrong decision at it should be changed. Maybe this has something to do with that.
See #368