diff options
author | Daniel Friesel <derf@finalrewind.org> | 2023-02-04 23:07:44 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2023-02-04 23:07:44 +0100 |
commit | 8a88c4fd9e1a86930d2578ba9d8f81a1d27e7750 (patch) | |
tree | 3894fad40b97077555e27649f384d1a019bbd7e0 /lib/Travel/Status/DE/HAFAS/Journey.pm | |
parent | 5f3150716723382723f8d4e30fa66b715c87f9b7 (diff) |
stboard time parser: handle day changes
Diffstat (limited to 'lib/Travel/Status/DE/HAFAS/Journey.pm')
-rw-r--r-- | lib/Travel/Status/DE/HAFAS/Journey.pm | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/lib/Travel/Status/DE/HAFAS/Journey.pm b/lib/Travel/Status/DE/HAFAS/Journey.pm index 893d95c..2cd8075 100644 --- a/lib/Travel/Status/DE/HAFAS/Journey.pm +++ b/lib/Travel/Status/DE/HAFAS/Journey.pm @@ -210,12 +210,28 @@ sub new { my $time_r = $journey->{stbStop}{ $hafas->{arrivals} ? 'aTimeR' : 'dTimeR' }; - my $datetime_s - = $hafas->{strptime_obj}->parse_datetime("${date}T${time_s}"); - my $datetime_r - = $time_r - ? $hafas->{strptime_obj}->parse_datetime("${date}T${time_r}") - : undef; + for my $timestr ( $time_s, $time_r ) { + if ( not defined $timestr ) { + next; + } + if ( length($timestr) == 8 ) { + + # arrival time includes a day offset + my $offset_date = $hafas->{now}->clone; + $offset_date->add( days => substr( $timestr, 0, 2, q{} ) ); + $offset_date = $offset_date->strftime('%Y%m%d'); + $timestr = $hafas->{strptime_obj} + ->parse_datetime("${offset_date}T${timestr}"); + } + else { + $timestr + = $hafas->{strptime_obj} + ->parse_datetime("${date}T${timestr}"); + } + } + + my $datetime_s = $time_s; + my $datetime_r = $time_r; my $delay = $datetime_r |