From 6b575af0e63f4df5d6dd5e217aa2e7ae3bc114ed Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sun, 31 Mar 2024 10:26:33 +0200 Subject: Ignore journeys with invalid timestamps during DST change --- lib/Travel/Status/DE/HAFAS.pm | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'lib/Travel/Status') diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm index 48fd19b..7dbb1f6 100644 --- a/lib/Travel/Status/DE/HAFAS.pm +++ b/lib/Travel/Status/DE/HAFAS.pm @@ -863,16 +863,30 @@ sub parse_board { my @jnyL = @{ $self->{raw_json}{svcResL}[0]{res}{jnyL} // [] }; for my $result (@jnyL) { - push( - @{ $self->{results} }, - Travel::Status::DE::HAFAS::Journey->new( - common => $self->{raw_json}{svcResL}[0]{res}{common}, - prodL => $prodL, - locL => \@locL, - journey => $result, - hafas => $self, - ) - ); + eval { + push( + @{ $self->{results} }, + Travel::Status::DE::HAFAS::Journey->new( + common => $self->{raw_json}{svcResL}[0]{res}{common}, + prodL => $prodL, + locL => \@locL, + journey => $result, + hafas => $self, + ) + ); + }; + if ($@) { + if ( $@ =~ m{Invalid local time for date in time zone} ) { + + # Yes, HAFAS does in fact return invalid times during DST change + # (as in, it returns 02:XX:XX timestamps when the time jumps from 02:00:00 to 03:00:00) + # It's not clear what exactly is going wrong where and whether a 2:30 or a 3:30 journey is the correct one. + # For now, silently discard the affected journeys. + } + else { + warn("Skipping $result->{jid}: $@"); + } + } } return $self; } -- cgit v1.2.3