py/icalfilter: update app.py
This commit is contained in:
parent
28ac784503
commit
5b84094ab0
1 changed files with 10 additions and 11 deletions
|
@ -3,8 +3,8 @@ import concurrent.futures
|
|||
import dataclasses
|
||||
import datetime
|
||||
import json
|
||||
from typing import Any, Dict, List, Optional, Set, Union
|
||||
import os
|
||||
from typing import Any, Dict, List, Optional, Set, Union
|
||||
|
||||
import aiohttp
|
||||
import attrs
|
||||
|
@ -31,7 +31,10 @@ def maybe_fromisoformat(val: Optional[str]) -> Optional[datetime.datetime]:
|
|||
return None
|
||||
if isinstance(val, datetime.datetime):
|
||||
return val
|
||||
return datetime.datetime.fromisoformat(val)
|
||||
dt = datetime.datetime.fromisoformat(val)
|
||||
if not dt.tzinfo:
|
||||
dt = dt.replace(tzinfo=UTC)
|
||||
return dt
|
||||
|
||||
|
||||
@attrs.frozen
|
||||
|
@ -97,15 +100,11 @@ def _all_occurrences_before_expensive(
|
|||
seen_timezones: Dict[str, icalendar.Timezone],
|
||||
) -> bool:
|
||||
# Recurring events are... more complicated.
|
||||
# Generate an iCal of just this event...
|
||||
fake_cal = icalendar.Calendar()
|
||||
for tz in seen_timezones.values():
|
||||
fake_cal.add_component(tz)
|
||||
fake_cal.add_component(event)
|
||||
|
||||
# and check to see if we get any instances that are after the cutoff.
|
||||
instances = icalevents.icalparser.parse_events(fake_cal.to_ical(), start=cutoff)
|
||||
return not instances
|
||||
rrule_or_rruleset = icalevents.icalparser.parse_rrule(event)
|
||||
try:
|
||||
return not rrule_or_rruleset.after(cutoff)
|
||||
except TypeError:
|
||||
return not rrule_or_rruleset.after(cutoff.replace(tzinfo=None))
|
||||
|
||||
|
||||
async def all_occurrences_before(
|
||||
|
|
Loading…
Reference in a new issue