MCPcopy Index your code
hub / github.com/O365/python-o365 / _parse_date_time_time_zone

Method _parse_date_time_time_zone

O365/utils/utils.py:423–463  ·  view source on GitHub ↗

Parses and convert to protocol timezone a dateTimeTimeZone resource This resource is a dict with a date time and a windows timezone This is a common structure on Microsoft apis so it's included here. Returns a dt.datetime with the datime converted to protocol timezo

(self,
                                   date_time_time_zone: Union[dict, str],
                                   is_all_day: bool = False)

Source from the content-addressed store, hash-verified

421 return self.protocol.convert_case(dict_key)
422
423 def _parse_date_time_time_zone(self,
424 date_time_time_zone: Union[dict, str],
425 is_all_day: bool = False) -> Union[dt.datetime, None]:
426 """
427 Parses and convert to protocol timezone a dateTimeTimeZone resource
428 This resource is a dict with a date time and a windows timezone
429 This is a common structure on Microsoft apis so it's included here.
430
431 Returns a dt.datetime with the datime converted to protocol timezone
432 """
433 if date_time_time_zone is None:
434 return None
435
436 local_tz = self.protocol.timezone
437 if isinstance(date_time_time_zone, dict):
438 try:
439 timezone = get_iana_tz(date_time_time_zone.get(self._cc('timeZone'), 'UTC'))
440 except ZoneInfoNotFoundError:
441 log.debug('TimeZone not found. Using protocol timezone instead.')
442 timezone = local_tz
443 date_time = date_time_time_zone.get(self._cc('dateTime'), None)
444 try:
445 date_time = parse(date_time).replace(tzinfo=timezone) if date_time else None
446 except OverflowError as e:
447 log.debug(f'Could not parse dateTimeTimeZone: {date_time_time_zone}. Error: {e}')
448 date_time = None
449
450 if date_time and timezone != local_tz:
451 if not is_all_day:
452 date_time = date_time.astimezone(local_tz)
453 else:
454 date_time = date_time.replace(tzinfo=local_tz)
455 else:
456 # Outlook v1.0 api compatibility (fallback to datetime string)
457 try:
458 date_time = parse(date_time_time_zone).replace(tzinfo=local_tz) if date_time_time_zone else None
459 except Exception as e:
460 log.debug(f'Could not parse dateTimeTimeZone: {date_time_time_zone}. Error: {e}')
461 date_time = None
462
463 return date_time
464
465 def _build_date_time_time_zone(self, date_time: dt.datetime) -> Dict[str, str]:
466 """ Converts a datetime to a dateTimeTimeZone resource Dict[datetime, windows timezone] """

Callers 6

__init__Method · 0.80
get_availabilityMethod · 0.80
__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80

Calls 3

_ccMethod · 0.95
get_iana_tzFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected