Special column applies only on non-rest days

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
rickzkmandClaude Sonnet 5.5 committed 2026-10-07 00:55:17 +02:00
1 parent 63a36333fb
commit 8649d3abd0
3 files changed
+22 -9

No files matched your search

+8 -4
View File
@@ -17,15 +17,18 @@ def select_column(columns: Sequence[Column], day: date, rest_day: bool) -> Colum
"""The column that applies on `day`, or None if the timetable has no usable column.
Rules (see spec "Choosing the column"):
1. a KIND_SPECIAL column whose `dates` contain `day` wins;
1. on a non-rest day, a KIND_SPECIAL column whose `dates` contain `day` wins
(the special column is workdays-during-school-holidays, so it never applies
on a Saturday, Sunday or state holiday);
2. otherwise rest days use KIND_REST_DAY columns, other days KIND_WORKDAY;
3. among columns of that kind the one with the latest valid_from <= day;
if none has started yet, the one with the earliest valid_from;
4. no column of the needed kind -> None.
"""
for column in columns:
if column.kind == KIND_SPECIAL and day in column.dates:
return column
if not rest_day:
for column in columns:
if column.kind == KIND_SPECIAL and day in column.dates:
return column
wanted = KIND_REST_DAY if rest_day else KIND_WORKDAY
candidates = sorted((c for c in columns if c.kind == wanted), key=lambda c: c.valid_from)
@@ -59,6 +62,7 @@ def next_departures(
for dep in column.departures:
when = datetime.combine(day, dep.time)
if when >= start:
# naive local-time difference: off by one hour on the two DST nights (00:00-03:00)
minutes = int((when - start).total_seconds() // 60)
found.append(Upcoming(dep, when, minutes, day != now.date()))
if len(found) >= count: