Split return date nav into separate outbound/return rows; show earlier tube option on inbound
For return journeys, replace the single combined date navigation row with two separate rows so outbound and return dates can be adjusted independently. For inbound underground options, show one service before the earliest catchable (as an "aim for this" option) rather than the next service after it, which often arrived too late to connect with the GWR train. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
1407cb8246
commit
a859b96a23
6 changed files with 82 additions and 22 deletions
|
|
@ -165,13 +165,17 @@ def next_service(
|
|||
|
||||
|
||||
def upcoming_services(
|
||||
earliest_board: datetime, count: int = 2, direction: str = 'pad_to_kx'
|
||||
earliest_board: datetime,
|
||||
count: int = 2,
|
||||
direction: str = 'pad_to_kx',
|
||||
preceding: int = 0,
|
||||
) -> list[tuple[datetime, datetime]]:
|
||||
"""
|
||||
Return up to *count* Circle line services for *direction*, starting from
|
||||
*earliest_board*.
|
||||
Return Circle line services for *direction* around *earliest_board*.
|
||||
|
||||
Each element is (depart_origin, arrive_destination) as datetimes.
|
||||
Returns up to *preceding* services before earliest_board followed by up to
|
||||
*count* services at or after earliest_board. Each element is
|
||||
(depart_origin, arrive_destination) as datetimes.
|
||||
"""
|
||||
timetable = _get_timetable().get(direction, {})[_day_type(earliest_board.weekday())]
|
||||
board_secs = (
|
||||
|
|
@ -180,13 +184,17 @@ def upcoming_services(
|
|||
+ earliest_board.second
|
||||
)
|
||||
midnight = earliest_board.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
pre_results = []
|
||||
results = []
|
||||
for pad_secs, kxp_secs in timetable:
|
||||
if pad_secs >= board_secs:
|
||||
results.append((
|
||||
midnight + timedelta(seconds=pad_secs),
|
||||
midnight + timedelta(seconds=kxp_secs),
|
||||
))
|
||||
entry = (
|
||||
midnight + timedelta(seconds=pad_secs),
|
||||
midnight + timedelta(seconds=kxp_secs),
|
||||
)
|
||||
if pad_secs < board_secs:
|
||||
pre_results.append(entry)
|
||||
else:
|
||||
results.append(entry)
|
||||
if len(results) == count:
|
||||
break
|
||||
return results
|
||||
return pre_results[-preceding:] + results if preceding else results
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue