0

I have a python script which syncs some of my appointments to two different google accounts, both accounts have a google calendar which is apparently set identically (the time zone set is also the same), at the time of the call to download the list of the appointments on the calendar however, the call returns the appointments with a different date format depending on the calendar I am going to query.

Example of the response returned from the first calendar: enter image description here

Example of the response returned from the second calendar: enter image description here

The library used is the one developed by google (Python version used is 3.6)

The script (which runs in both cases on the same machine) is the following:

params = {
    'calendarId':   self._calendar.id,
    'timeMin':      from_datetime,
    'timeMax':      to_datetime,
    'maxResults':   MAX_APP_DOWNLOADS,
    'singleEvents': True,
    'orderBy':      'startTime',
    'showDeleted':  'true'
}
events_result = self._service.events().list(**params).execute()
events = events_result.get('items', [])

I suppose it is some problem regarding the calendar configuration, but I have not found any settings about it in the settings.

Matteo Pasini
  • 1,787
  • 3
  • 13
  • 26
  • Maybe related: Military time suffixes (ZULU) [here](https://stackoverflow.com/questions/19654578/python-utc-datetime-objects-iso-format-doesnt-include-z-zulu-or-zero-offset) – Patrick Artner Nov 10 '21 at 08:21

1 Answers1

1

Both times returned are in ISO 8601 format.

Update : From the Google API Docs, it is RFC3339. They are mostly similar, but RFC3339 is stricter.

You can use datetime.datetime.fromisoformat or dateutil.parser.isoparse

>>> from datetime import datetime

>>> from dateutil.parser import isoparse

>>> datetime.fromisoformat('2011-11-04T00:05:23+04:00')
datetime.datetime(2011, 11, 4, 0, 5, 23, tzinfo=datetime.timezone(datetime.timedelta(seconds=14400)))

>>> isoparse('2011-11-04T00:05:23Z')
datetime.datetime(2011, 11, 4, 0, 5, 23, tzinfo=datetime.timezone(datetime.timedelta(seconds=0)))

Looks like datetime.datetime.fromisoformat doesn't support reading with the ending 'Z' character, so you should use the dateutil format.

Ron
  • 168
  • 9
  • thank you very much for your help, I have now managed to convert the two different types of date format correctly, but I cannot understand how it is possible that the response of the api is different for the two calendars, since that both accounts and both calendars are set identically. I understand that they are both in the ISO 8601 format, but I don't understand why to use different ones. – Matteo Pasini Nov 10 '21 at 09:32