Add support for multi-day events in YAML
This commit is contained in:
parent
1af5d7856f
commit
6a82e3d8f4
|
@ -135,6 +135,15 @@ def combine_holidays(events: list[Event]) -> list[Event]:
|
||||||
return list(combined.values())
|
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]:
|
def read_events_yaml(data_dir: str, start: date, end: date) -> list[Event]:
|
||||||
"""Read eventes from YAML file."""
|
"""Read eventes from YAML file."""
|
||||||
events: list[Event] = []
|
events: list[Event] = []
|
||||||
|
@ -142,12 +151,15 @@ def read_events_yaml(data_dir: str, start: date, end: date) -> list[Event]:
|
||||||
dates = (
|
dates = (
|
||||||
dates_from_rrule(item["rrule"], start, end)
|
dates_from_rrule(item["rrule"], start, end)
|
||||||
if "rrule" in item
|
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:
|
for dt in dates:
|
||||||
e = Event(
|
e = Event(
|
||||||
name=item["name"],
|
name=item["name"],
|
||||||
date=dt,
|
date=dt,
|
||||||
|
end_date=(
|
||||||
|
item.get("end_date") if item["name"] != "travel_insurance" else None
|
||||||
|
),
|
||||||
title=item.get("title"),
|
title=item.get("title"),
|
||||||
url=item.get("url"),
|
url=item.get("url"),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue