derf / Travel-Status-DE-DeutscheBahn

Commandline Public Transit Departure Monitor
https://finalrewind.org/projects/Travel-Status-DE-DeutscheBahn
Other
16 stars 3 forks source link

Cross-Midnight detection doesn't work with ÖBB #6

Closed deingithub closed 7 months ago

deingithub commented 1 year ago

Hi!

The cross-midnight detection and fix introduced in 4.14 assumes HAFAS jids look like this: 1|1485117|17|80|7102023. When querying ÖBB HAFAS, however, the journey IDs look like this:

2|#VN#1#ST#1696575382#PI#0#ZI#517232#TA#44#DA#71023#1S#907041#1T#1416#LS#911007#LT#1446#PU#81#RT#1#CA#str#ZE#6#ZB#Tram 6  #PC#9#FR#907041#FT#1416#TO#911007#TT#1446#

The Date component is hidden at a different position in the jid, formatted as 71023. But there's also a unix timestamp at 1696575382, so that might make parsing it less necessary? I don't really know enough about the issue worked around by cross-midnight detection to tell. As a consequence, in here, https://github.com/derf/Travel-Status-DE-DeutscheBahn/blob/585a063f27c0ffe25fc8b71f08d28dcec5478832/lib/Travel/Status/DE/HAFAS/Journey.pm#L92-L102 $date_ref winds up being undefined, so $datetime_ref also winds up undefined, and on every time of day we get a torrent of warnings like these:

HAFAS, not even once -- midnight crossing may be bogus at /nix/store/…/Travel/Status/DE/HAFAS/Journey.pm line 94.
Use of uninitialized value $date_ref in numeric eq (==) at /nix/store/…/Travel/Status/DE/HAFAS/Journey.pm line 96.
Use of uninitialized value $string in pattern match (m//) at /nix/store/…/DateTime/Format/Strptime.pm line 225.

If the journey, however, actually crosses midnight, this line https://github.com/derf/Travel-Status-DE-DeutscheBahn/blob/585a063f27c0ffe25fc8b71f08d28dcec5478832/lib/Travel/Status/DE/HAFAS/Journey.pm#L297 causes a crash, as $datetime_ref is undefined.

derf commented 12 months ago

Thanks for pointing this out!

detection of midnight crossings is needed to handle journeys that start before midnight but were requested after midnight, at least for DB HAFAS. I haven't yet looked into ÖBB or other APIs.

The UNIX timestamp is useless, unfortunately -- but the encoded date might work. I'll have to check that once I'm awake and online at a suitable time, so this will take a while.