Replace all dates if any has the wrong type

This commit is contained in:
Unrud 2021-12-20 23:47:39 +01:00
parent fb3de73d1c
commit eac460d4d9

View File

@ -154,17 +154,14 @@ def check_and_sanitize_items(
ref_value_param = component.dtstart.params.get("VALUE") ref_value_param = component.dtstart.params.get("VALUE")
for dates in chain(component.contents.get("exdate", []), for dates in chain(component.contents.get("exdate", []),
component.contents.get("rdate", [])): component.contents.get("rdate", [])):
replace_value_param = False if all(type(d) == type(ref_date) for d in dates.value):
continue
for i, date in enumerate(dates.value): for i, date in enumerate(dates.value):
if type(date) != type(ref_date):
replace_value_param = True
dates.value[i] = ref_date.replace( dates.value[i] = ref_date.replace(
date.year, date.month, date.day) date.year, date.month, date.day)
if replace_value_param:
if ref_value_param is None:
with contextlib.suppress(KeyError): with contextlib.suppress(KeyError):
del dates.params["VALUE"] del dates.params["VALUE"]
else: if ref_value_param is not None:
dates.params["VALUE"] = ref_value_param dates.params["VALUE"] = ref_value_param
# vobject interprets recurrence rules on demand # vobject interprets recurrence rules on demand
try: try: