简体   繁体   中英

problem with the query of getting all-day type events on a day from microsoft calendar by O365

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!

2022-09-19_12-14


[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:

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 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM