From f6d715e52ae67436a53d4ab044b21931179f50d0 Mon Sep 17 00:00:00 2001
From: Edward Betts <edward@4angle.com>
Date: Sun, 8 Dec 2024 14:12:36 +0000
Subject: [PATCH] Check flight bookings are in chronological order.

---
 validate_yaml.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/validate_yaml.py b/validate_yaml.py
index 818840d..4e3ed1d 100755
--- a/validate_yaml.py
+++ b/validate_yaml.py
@@ -43,14 +43,20 @@ def check_trips() -> None:
 
 
 def check_flights(airlines: set[str]) -> None:
-    """Check flights."""
+    """Check flights and ensure they are in chronological order."""
     bookings = agenda.travel.parse_yaml("flights", data_dir)
+
+    prev_first_depart = None
     for booking in bookings:
         assert all(flight["airline"] in airlines for flight in booking["flights"])
-
-    for booking in bookings:
         check_currency(booking)
 
+        if prev_first_depart:
+            assert (
+                booking["flights"][0]["depart"] > prev_first_depart
+            ), "Bookings are not in chronological order by first flight's departure."
+        prev_first_depart = booking["flights"][0]["depart"]
+
     print(len(bookings), "flights")