fix: timezone unaware vs aware errors.

Now always use utc.
This commit is contained in:
redxef 2025-03-05 14:38:31 +01:00
parent 41d6c4be84
commit 7b671e950a
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921
3 changed files with 12 additions and 12 deletions

View file

@ -39,7 +39,7 @@ class Source(abc.ABC):
limit=None, limit=None,
) -> typing.Iterable[dict]: ) -> typing.Iterable[dict]:
until = until if until else datetime.timedelta(days=365) 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 now_365 = now + until
for e in self.get_events( for e in self.get_events(
start=start, start=start,
@ -50,17 +50,18 @@ class Source(abc.ABC):
yield e yield e
continue continue
r = e.pop('recurrence') 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( r = dateutil.rrule.rrulestr(
'\n'.join(r), '\n'.join(r),
unfold=True, unfold=True,
ignoretz=True, ignoretz=False,
dtstart=datetime.datetime.fromisoformat( dtstart=dtstart,
e['start']['dateTime']
if 'dateTime' in e['start'] else
e['start']['date']
).replace(tzinfo=None)
) )
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) e_ = copy.deepcopy(e)
if 'dateTime' in e['start']: if 'dateTime' in e['start']:
e_['start']['dateTime'] = datetime.datetime.combine(t_.date(), datetime.datetime.fromisoformat(e['start']['dateTime']).time()).isoformat() e_['start']['dateTime'] = datetime.datetime.combine(t_.date(), datetime.datetime.fromisoformat(e['start']['dateTime']).time()).isoformat()

View file

@ -6,7 +6,6 @@ import logging
import os import os
from google.auth.transport.requests import Request from google.auth.transport.requests import Request
#from google.oauth2.credentials import Credentials
from google.oauth2.service_account import Credentials from google.oauth2.service_account import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build 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): 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) 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 now_365 = now + until
try: try:

View file

@ -83,7 +83,7 @@ class Wordpress(Sink, Adapter):
def _datestr_to_date(self, s, tz=None): def _datestr_to_date(self, s, tz=None):
if s.endswith('Z'): if s.endswith('Z'):
s = s[:-1] 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): def _generate_data_single(self, event, item_id=2):
start = event['start'] start = event['start']
@ -138,7 +138,7 @@ class Wordpress(Sink, Adapter):
start: datetime.datetime | None=None, start: datetime.datetime | None=None,
until: datetime.timedelta | 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) until = until if until else datetime.timedelta(days=365)
final_dict = {} final_dict = {}