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 dataclasses
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
from typing import Any, Dict, List, Optional, Set, Union
|
|
||||||
import os
|
import os
|
||||||
|
from typing import Any, Dict, List, Optional, Set, Union
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import attrs
|
import attrs
|
||||||
|
@ -31,7 +31,10 @@ def maybe_fromisoformat(val: Optional[str]) -> Optional[datetime.datetime]:
|
||||||
return None
|
return None
|
||||||
if isinstance(val, datetime.datetime):
|
if isinstance(val, datetime.datetime):
|
||||||
return val
|
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
|
@attrs.frozen
|
||||||
|
@ -97,15 +100,11 @@ def _all_occurrences_before_expensive(
|
||||||
seen_timezones: Dict[str, icalendar.Timezone],
|
seen_timezones: Dict[str, icalendar.Timezone],
|
||||||
) -> bool:
|
) -> bool:
|
||||||
# Recurring events are... more complicated.
|
# Recurring events are... more complicated.
|
||||||
# Generate an iCal of just this event...
|
rrule_or_rruleset = icalevents.icalparser.parse_rrule(event)
|
||||||
fake_cal = icalendar.Calendar()
|
try:
|
||||||
for tz in seen_timezones.values():
|
return not rrule_or_rruleset.after(cutoff)
|
||||||
fake_cal.add_component(tz)
|
except TypeError:
|
||||||
fake_cal.add_component(event)
|
return not rrule_or_rruleset.after(cutoff.replace(tzinfo=None))
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
|
|
||||||
async def all_occurrences_before(
|
async def all_occurrences_before(
|
||||||
|
|
Loading…
Reference in a new issue