Handle rail journeys without specific time
This commit is contained in:
parent
1ed6c50ad8
commit
f1338e5970
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@
|
|||
<div class="grid-item">
|
||||
{% 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 %}
|
||||
</div>
|
||||
<div class="grid-item">{{ ((item.arrive - item.depart).total_seconds() // 60) | int }} mins</div>
|
||||
|
|
Loading…
Reference in a new issue