From ea801662295410328ceefb25942a595b422e7d06 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Mon, 3 Aug 2026 14:40:20 +0100 Subject: [PATCH] Validate maximum trip length --- validate_yaml.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/validate_yaml.py b/validate_yaml.py index a24a5d5..0ee272d 100755 --- a/validate_yaml.py +++ b/validate_yaml.py @@ -25,6 +25,7 @@ data_dir = config.PERSONAL_DATA currencies = set(config.CURRENCIES + ["GBP"]) LatLon = Tuple[float, float] +MAX_TRIP_NIGHTS = 60 def check_currency(item: agenda.types.StrDict) -> None: @@ -102,6 +103,22 @@ def ranges_overlap( return start_a < end_b and start_b < end_a +def check_trip_duration(trip: agenda.types.Trip) -> None: + """Check trip duration is within the expected maximum.""" + if trip.end is None: + return + + nights = (trip.end - trip.start).days + if nights <= MAX_TRIP_NIGHTS: + return + + url = f"https://edwardbetts.com/agenda/trip/{trip.start.isoformat()}" + print(f"Trip is too long: {url}") + print(f" {trip.title}") + print(f" {trip.start.isoformat()} to {trip.end.isoformat()}: {nights} nights") + assert False, f"Trip is {nights} nights; maximum is {MAX_TRIP_NIGHTS}" + + def check_trips() -> None: """Check trips and ensure they are in chronological order.""" filepath = os.path.join(data_dir, "trips.yaml") @@ -130,6 +147,8 @@ def check_trips() -> None: print(len(trip_list), "trips") for trip in trip_list: + check_trip_duration(trip) + if not trip.accommodation or not trip.conferences: continue accommodation_entries: list[