From 8649d3abd0ff8901c6b9dc17abb17236ac015ef9 Mon Sep 17 00:00:00 2001 From: Richard Kacerek Date: Wed, 7 Oct 2026 00:55:17 +0200 Subject: [PATCH] Special column applies only on non-rest days Co-Authored-By: Claude Sonnet 5.5 --- .../specs/2026-10-06-bus-board-design.md | 6 ++++-- schedule.py | 12 ++++++++---- tests/test_schedule.py | 13 ++++++++++--- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/docs/superpowers/specs/2026-10-06-bus-board-design.md b/docs/superpowers/specs/2026-10-06-bus-board-design.md index 42beccb..8155a72 100644 --- a/docs/superpowers/specs/2026-10-06-bus-board-design.md +++ b/docs/superpowers/specs/2026-10-06-bus-board-design.md @@ -97,13 +97,15 @@ effects in their pure functions so they are unit-testable. ### Choosing the column (schedule.py) For a given date: -1. If the date is in a `special` column's explicit dates → that column. +1. If the date is not a rest day and is in a `special` column's explicit dates → that column + (the special column is workdays during school holidays, so it never applies on a + Saturday, Sunday or state holiday). 2. Else if it is a Saturday, Sunday or Czech state holiday → the `rest_day` column. 3. Else → the `workday` column. Among columns of the same kind, use the one with the latest `valid_from <= date`; if none yet applies, use the earliest. Steps 1–3 are the proposed default order -(special date beats holiday/weekend); the user writes and may change this function, +(a special date on a workday beats the workday column; rest days always use the rest-day column); the user writes and may change this function, see "User-written code" below. `next_departures` looks at today's selected column from `now`, and rolls into the diff --git a/schedule.py b/schedule.py index 7ca6812..0bb5953 100644 --- a/schedule.py +++ b/schedule.py @@ -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: diff --git a/tests/test_schedule.py b/tests/test_schedule.py index 29e4ff2..8000bd0 100644 --- a/tests/test_schedule.py +++ b/tests/test_schedule.py @@ -55,9 +55,16 @@ def test_special_column_ignored_on_other_days(): assert select_column([WORK_NEW, REST, SPECIAL], date(2026, 11, 2), rest_day=False) is WORK_NEW -def test_special_date_beats_rest_day(): - # Default precedence (your call to change): a special date wins even on a rest day. - assert select_column([WORK_NEW, REST, SPECIAL], date(2026, 10, 29), rest_day=True) is SPECIAL +def test_special_date_is_ignored_on_a_rest_day(): + # Decision: the special column is "Prac.dny-skolni prazdniny", i.e. workdays during + # school holidays only, so it never applies on a Saturday, Sunday or state holiday + # (rule set by the controller on 2026-10-07 after the final review). + assert select_column([WORK_NEW, REST, SPECIAL], date(2026, 10, 29), rest_day=True) is REST + + +def test_special_dates_on_a_saturday_use_the_rest_column(): + special = col(KIND_SPECIAL, date(2026, 10, 29), [date(2026, 10, 29), date(2026, 10, 31)]) + assert select_column([WORK_NEW, REST, special], date(2026, 10, 31), rest_day=True) is REST def test_no_column_of_the_needed_kind_returns_none():