Validate maximum trip length

This commit is contained in:
Edward Betts 2026-08-03 14:40:20 +01:00
parent 3747e83ade
commit ea80166229

View file

@ -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[