Skip to content

Commit 5b06c79

Browse files
author
Alejandro Casanovas
committed
fix ApiComponent_build_date_time_time_zone to account for tzinfo coming from ZoneInfo
1 parent fd97b0f commit 5b06c79

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

O365/utils/utils.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,20 @@ def _parse_date_time_time_zone(self, date_time_time_zone, is_all_day=False):
458458

459459
def _build_date_time_time_zone(self, date_time):
460460
""" Converts a datetime to a dateTimeTimeZone resource """
461-
timezone = date_time.tzinfo.zone if date_time.tzinfo is not None else None
461+
timezone = None
462+
if date_time.tzinfo is not None:
463+
if isinstance(date_time.tzinfo, ZoneInfo):
464+
timezone = date_time.tzinfo.key
465+
elif isinstance(date_time.tzinfo, dt.tzinfo):
466+
timezone = date_time.tzinfo.tzname(date_time)
467+
else:
468+
raise ValueError('Unexpected tzinfo class.')
469+
470+
timezone = get_windows_tz(timezone or self.protocol.timezone)
471+
462472
return {
463473
self._cc('dateTime'): date_time.strftime('%Y-%m-%dT%H:%M:%S'),
464-
self._cc('timeZone'): get_windows_tz(timezone or self.protocol.timezone)
474+
self._cc('timeZone'): timezone
465475
}
466476

467477
def new_query(self, attribute=None):

0 commit comments

Comments
 (0)