Add support for multi-day events in YAML

This commit is contained in:
Edward Betts 2023-11-10 00:35:38 +01:00
parent 1af5d7856f
commit 6a82e3d8f4

View file

@ -135,6 +135,15 @@ def combine_holidays(events: list[Event]) -> list[Event]:
return list(combined.values())
def get_yaml_event_date_field(item: dict[str, str]) -> str:
"""Event date field name."""
return (
"end_date"
if item["name"] == "travel_insurance"
else ("start_date" if "start_date" in item else "date")
)
def read_events_yaml(data_dir: str, start: date, end: date) -> list[Event]:
"""Read eventes from YAML file."""
events: list[Event] = []
@ -142,12 +151,15 @@ def read_events_yaml(data_dir: str, start: date, end: date) -> list[Event]:
dates = (
dates_from_rrule(item["rrule"], start, end)
if "rrule" in item
else [item["end_date" if item["name"] == "travel_insurance" else "date"]]
else [item[get_yaml_event_date_field(item)]]
)
for dt in dates:
e = Event(
name=item["name"],
date=dt,
end_date=(
item.get("end_date") if item["name"] != "travel_insurance" else None
),
title=item.get("title"),
url=item.get("url"),
)