Skip to content

Commit

Permalink
New windows_tz.py module: Stores conversions between Iana/Olson timez…
Browse files Browse the repository at this point in the history
…ones and Windows timezones

New timezone option on Protocol instantiation. If not provided the detected system timezone will be used
Protocols now handles the conversions between Iana vs Windows timezones
All datetimes objects in all objects are timezone aware datetimes: It will convert back and forth the timezones for you
Event: now tracks it's internal changes so can update automatically only on needed attributes.
Event: Some attributes are intelligent enough to track changes of needed attributes by the api.
Event: Now events can accept or decline invitations.

Updated docs
Fixed some bugs
  • Loading branch information
Jandro committed Apr 17, 2018
1 parent 415ac67 commit 2410e35
Show file tree
Hide file tree
Showing 10 changed files with 976 additions and 158 deletions.
4 changes: 2 additions & 2 deletions O365/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ def __init__(self, credentials, *, auth_method=AUTH_METHOD.OAUTH, scopes=None,

if auth_method is AUTH_METHOD.BASIC:
protocol = protocol or BasicAuthProtocol # using basic auth defaults to Office 365 protocol
self.protocol = protocol(default_resource=main_resource) if isinstance(protocol, type) else protocol
self.protocol = protocol(default_resource=main_resource, **kwargs) if isinstance(protocol, type) else protocol
if self.protocol.api_version != 'v1.0' or not isinstance(self.protocol, BasicAuthProtocol):
raise RuntimeError(
'Basic Authentication only works with Office 365 Api version v1.0 and until November 1 2018.')
elif auth_method is AUTH_METHOD.OAUTH:
protocol = protocol or MSGraphProtocol # using oauth auth defaults to Graph protocol
self.protocol = protocol(default_resource=main_resource) if isinstance(protocol, type) else protocol
self.protocol = protocol(default_resource=main_resource, **kwargs) if isinstance(protocol, type) else protocol

if not isinstance(self.protocol, Protocol):
raise ValueError("'protocol' must be a subclass of Protocol")
Expand Down
5 changes: 2 additions & 3 deletions O365/address_book.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
from dateutil.parser import parse
from tzlocal import get_localzone
from enum import Enum

from O365.message import HandleRecipientsMixin, Recipients, Message
Expand Down Expand Up @@ -48,7 +47,7 @@ def __init__(self, *, parent=None, con=None, **kwargs):
self.created = cloud_data.get(cc('createdDateTime'), None)
self.modified = cloud_data.get(cc('lastModifiedDateTime'), None)

local_tz = get_localzone()
local_tz = self.protocol.timezone
self.created = parse(self.created).astimezone(local_tz) if self.created else None
self.modified = parse(self.modified).astimezone(local_tz) if self.modified else None

Expand Down Expand Up @@ -202,7 +201,7 @@ def save(self):
self.created = contact.get(self._cc('createdDateTime'), None)
self.modified = contact.get(self._cc('lastModifiedDateTime'), None)

local_tz = get_localzone()
local_tz = self.protocol.timezone
self.created = parse(self.created).astimezone(local_tz) if self.created else None
self.modified = parse(self.modified).astimezone(local_tz) if self.modified else None

Expand Down
Loading

0 comments on commit 2410e35

Please sign in to comment.