From ef624f83dd9d9ddc56f6d3e0b657248c283e9df1 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Mon, 21 Oct 2024 10:39:49 +0100 Subject: [PATCH] Enhance conference validation and add MAX_CONF_DAYS - Add checks for conference start and end dates. - Set maximum conference duration to 20 days. Closes: #182 --- agenda/conference.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/agenda/conference.py b/agenda/conference.py index 9960f80..36f6e06 100644 --- a/agenda/conference.py +++ b/agenda/conference.py @@ -6,8 +6,11 @@ from datetime import date, datetime import yaml +from . import utils from .event import Event +MAX_CONF_DAYS = 20 + @dataclasses.dataclass class Conference: @@ -55,6 +58,9 @@ def get_list(filepath: str) -> list[Event]: """Read conferences from a YAML file and return a list of Event objects.""" events: list[Event] = [] for conf in (Conference(**conf) for conf in yaml.safe_load(open(filepath, "r"))): + assert conf.start <= conf.end + duration = (utils.as_date(conf.end) - utils.as_date(conf.start)).days + assert duration < MAX_CONF_DAYS event = Event( name="conference", date=conf.start,