From 8a88c4fd9e1a86930d2578ba9d8f81a1d27e7750 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 4 Feb 2023 23:07:44 +0100 Subject: stboard time parser: handle day changes --- lib/Travel/Status/DE/HAFAS/Journey.pm | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'lib/Travel/Status/DE') 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 -- cgit v1.2.3