diff --git a/adapters/abc.py b/adapters/abc.py index 6df7f7f..c45e1a9 100644 --- a/adapters/abc.py +++ b/adapters/abc.py @@ -39,7 +39,7 @@ class Source(abc.ABC): limit=None, ) -> typing.Iterable[dict]: until = until if until else datetime.timedelta(days=365) - now = start if start else datetime.datetime.utcnow().astimezone() + now = start if start else datetime.datetime.now(datetime.timezone.utc) now_365 = now + until for e in self.get_events( start=start, @@ -50,17 +50,18 @@ class Source(abc.ABC): yield e continue r = e.pop('recurrence') + dtstart = datetime.datetime.fromisoformat( + e['start']['dateTime'] + if 'dateTime' in e['start'] else + e['start']['date'] + ).replace(tzinfo=datetime.timezone.utc) r = dateutil.rrule.rrulestr( '\n'.join(r), unfold=True, - ignoretz=True, - dtstart=datetime.datetime.fromisoformat( - e['start']['dateTime'] - if 'dateTime' in e['start'] else - e['start']['date'] - ).replace(tzinfo=None) + ignoretz=False, + dtstart=dtstart, ) - for t_ in r.between(now.replace(tzinfo=None), now_365.replace(tzinfo=None)): + for t_ in r.between(now, now_365): e_ = copy.deepcopy(e) if 'dateTime' in e['start']: e_['start']['dateTime'] = datetime.datetime.combine(t_.date(), datetime.datetime.fromisoformat(e['start']['dateTime']).time()).isoformat() diff --git a/adapters/google.py b/adapters/google.py index 472d5fb..11f044f 100644 --- a/adapters/google.py +++ b/adapters/google.py @@ -6,7 +6,6 @@ import logging import os from google.auth.transport.requests import Request -#from google.oauth2.credentials import Credentials from google.oauth2.service_account import Credentials from google_auth_oauthlib.flow import InstalledAppFlow from googleapiclient.discovery import build @@ -53,7 +52,7 @@ class Google(Source, Adapter): def get_events(self, start: datetime.datetime | None=None, until: datetime.timedelta | None=None, limit=None): until = until if until else datetime.timedelta(days=365) - now = start if start else datetime.datetime.utcnow().astimezone() + now = start if start else datetime.datetime.now(datetime.timezone.utc) now_365 = now + until try: diff --git a/adapters/wordpress.py b/adapters/wordpress.py index 60306b9..9920f6b 100644 --- a/adapters/wordpress.py +++ b/adapters/wordpress.py @@ -83,7 +83,7 @@ class Wordpress(Sink, Adapter): def _datestr_to_date(self, s, tz=None): if s.endswith('Z'): s = s[:-1] - return datetime.datetime.fromisoformat(s).astimezone().date() + return datetime.datetime.fromisoformat(s).date() def _generate_data_single(self, event, item_id=2): start = event['start'] @@ -138,7 +138,7 @@ class Wordpress(Sink, Adapter): start: datetime.datetime | None=None, until: datetime.timedelta | None=None ): - start = start if start else datetime.datetime.utcnow().astimezone() + start = start if start else datetime.datetime.now(datetime.timezone.utc) until = until if until else datetime.timedelta(days=365) final_dict = {}