From 6a82e3d8f4555fa3f8b879df3e57b1a691b30c05 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 10 Nov 2023 00:35:38 +0100 Subject: [PATCH] Add support for multi-day events in YAML --- agenda/data.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/agenda/data.py b/agenda/data.py index 31151cc..d08c7ae 100644 --- a/agenda/data.py +++ b/agenda/data.py @@ -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"), )