diff --git a/agenda/trip.py b/agenda/trip.py index fe2be90..bf22c3d 100644 --- a/agenda/trip.py +++ b/agenda/trip.py @@ -1,6 +1,6 @@ -import operator import os -from datetime import date +from datetime import date, datetime, time +from zoneinfo import ZoneInfo import flask import yaml @@ -41,6 +41,13 @@ def load_trains() -> list[StrDict]: return trains +def depart_datetime(item: StrDict) -> datetime: + depart = item["depart"] + if isinstance(depart, datetime): + return depart + return datetime.combine(depart, time.min).replace(tzinfo=ZoneInfo("UTC")) + + def load_flights() -> list[StrDict]: """Load flights.""" data_dir = flask.current_app.config["PERSONAL_DATA"] @@ -63,9 +70,7 @@ def build_trip_list() -> list[Trip]: data_dir = flask.current_app.config["PERSONAL_DATA"] - travel_items = sorted( - load_flights() + load_trains(), key=operator.itemgetter("depart") - ) + travel_items = sorted(load_flights() + load_trains(), key=depart_datetime) data = { "travel": travel_items, diff --git a/agenda/types.py b/agenda/types.py index cb4f505..4a569d6 100644 --- a/agenda/types.py +++ b/agenda/types.py @@ -60,7 +60,7 @@ class Trip: ) assert isinstance(max_conference_end, datetime.date) - arrive = [item["arrive"].date() for item in self.travel if "arrive" in item] + arrive = [as_date(item["arrive"]) for item in self.travel if "arrive" in item] travel_end = max(arrive) if arrive else datetime.date.min assert isinstance(travel_end, datetime.date) diff --git a/templates/macros.html b/templates/macros.html index 110a780..1ce9ec8 100644 --- a/templates/macros.html +++ b/templates/macros.html @@ -107,7 +107,7 @@
{% if item.arrive %} {{ item.arrive.strftime("%H:%M") }} - {% if item.arrive.date() != item.depart.date() %}+1 day{% endif %} + {% if item.depart != item.arrive and item.arrive.date() != item.depart.date() %}+1 day{% endif %} {% endif %}
{{ ((item.arrive - item.depart).total_seconds() // 60) | int }} mins