diff options
Diffstat (limited to 'lib/Travel/Status')
-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 |