chore: cleanup mr

pull/97/head
Martin Eigenmann 2022-12-18 12:20:50 +01:00
rodzic 00f3392230
commit 53817ccd88
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 069D1EE3806CA368
1 zmienionych plików z 22 dodań i 37 usunięć

Wyświetl plik

@ -342,10 +342,8 @@ def parse_events(
exlist = [] exlist = []
if isinstance(component["EXDATE"], vDDDLists): if isinstance(component["EXDATE"], vDDDLists):
exlist = component["EXDATE"].dts exlist = component["EXDATE"].dts
elif isinstance(component["EXDATE"], list):
exlist = component["EXDATE"]
else: else:
exlist.append(component["EXDATE"]) exlist = component["EXDATE"]
for ex in exlist: for ex in exlist:
exdate = ex.to_ical().decode("UTF-8") exdate = ex.to_ical().decode("UTF-8")
exceptions[exdate[0:8]] = exdate exceptions[exdate[0:8]] = exdate
@ -477,9 +475,6 @@ def parse_rrule(component):
:return: extracted rrule or rruleset or None :return: extracted rrule or rruleset or None
""" """
if not component.get("rrule"):
return None
dtstart = component.get("dtstart").dt dtstart = component.get("dtstart").dt
# component['rrule'] can be both a scalar and a list # component['rrule'] can be both a scalar and a list
@ -491,31 +486,27 @@ def parse_rrule(component):
if type(dtstart) is datetime: if type(dtstart) is datetime:
# If we have timezone defined adjust for daylight saving time # If we have timezone defined adjust for daylight saving time
if type(until) is datetime: if type(until) is datetime:
until_offset = ( return until + abs(
(
until.astimezone(dtstart.tzinfo).utcoffset() until.astimezone(dtstart.tzinfo).utcoffset()
if until.tzinfo is not None and dtstart.tzinfo is not None if until.tzinfo is not None and dtstart.tzinfo is not None
else None else None
) )
if until_offset is not None: or timedelta()
return until + abs(until_offset) )
offset = dtstart.tzinfo.utcoffset(dtstart) if dtstart.tzinfo else None return (
normalized_until = (
until.astimezone(UTC) until.astimezone(UTC)
if type(until) is datetime if type(until) is datetime
else datetime( else datetime(
year=until.year, month=until.month, day=until.day, tzinfo=UTC year=until.year, month=until.month, day=until.day, tzinfo=UTC
) )
) + (
(dtstart.tzinfo.utcoffset(dtstart) if dtstart.tzinfo else None)
or timedelta()
) )
if offset:
return normalized_until + offset
return normalized_until return until.date() + timedelta(days=1) if type(until) is datetime else until
elif type(dtstart) is date:
return (
until.date() + timedelta(days=1) if type(until) is datetime else until
)
for index, rru in enumerate(rrules): for index, rru in enumerate(rrules):
if "UNTIL" in rru: if "UNTIL" in rru:
@ -534,22 +525,16 @@ def parse_rrule(component):
# Add exdates to the rruleset # Add exdates to the rruleset
for exd in extract_exdates(component): for exd in extract_exdates(component):
if type(dtstart) is date: if type(dtstart) is date:
if exd.tzinfo:
rule.exdate(exd.replace(tzinfo=None)) rule.exdate(exd.replace(tzinfo=None))
# rule.exdate(datetime(year=exd.year, month=exd.month, day=exd.day) + timedelta(days=1))
else:
rule.exdate(exd)
else: else:
rule.exdate(exd) rule.exdate(exd)
# TODO: What about rdates and exrules? # TODO: What about rdates and exrules?
if component.get("exrule"): if component.get("exrule"):
# pass pass
print("exrule", component.get("exrule"))
if component.get("rdate"): if component.get("rdate"):
# pass pass
print("rdate", component.get("rdate"))
return rule return rule
@ -562,11 +547,11 @@ def extract_exdates(component):
:return: list of exception dates :return: list of exception dates
""" """
dates = [] dates = []
if exd_prop := component.get("exdate"): exd_prop = component.get("exdate")
if isinstance(exd_prop, list): if isinstance(exd_prop, list):
for exd_list in exd_prop: for exd_list in exd_prop:
dates.extend(exd.dt for exd in exd_list.dts) dates.extend(exd.dt for exd in exd_list.dts)
elif isinstance(exd_prop, vDDDLists): else: # it must be a vDDDLists
dates.extend(exd.dt for exd in exd_prop.dts) dates.extend(exd.dt for exd in exd_prop.dts)
return dates return dates