From 3fd12f84c507d8b968e7ed652f79e43301fbe0e0 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 26 Jul 2021 22:23:30 +0200 Subject: train details/route: indicate whether a stop is past or future --- lib/DBInfoscreen/Helper/HAFAS.pm | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'lib/DBInfoscreen/Helper') diff --git a/lib/DBInfoscreen/Helper/HAFAS.pm b/lib/DBInfoscreen/Helper/HAFAS.pm index 2bc252a..91661a2 100644 --- a/lib/DBInfoscreen/Helper/HAFAS.pm +++ b/lib/DBInfoscreen/Helper/HAFAS.pm @@ -306,6 +306,7 @@ sub get_route_timestamps_p { my ( $self, %opt ) = @_; my $promise = Mojo::Promise->new; + my $now = DateTime->now( time_zone => 'Europe/Berlin' ); if ( $opt{train} ) { $opt{date_yy} = $opt{train}->start->strftime('%d.%m.%y'); @@ -314,7 +315,6 @@ sub get_route_timestamps_p { $opt{train_origin} = $opt{train}->origin; } else { - my $now = DateTime->now( time_zone => 'Europe/Berlin' ); $opt{date_yy} = $now->strftime('%d.%m.%y'); $opt{date_yyyy} = $now->strftime('%d.%m.%Y'); } @@ -355,6 +355,8 @@ sub get_route_timestamps_p { time_zone => 'Europe/Berlin', ); + my $station_is_past = 1; + for my $station ( @{ $traininfo->{suggestions}[0]{locations} // [] } ) { @@ -380,21 +382,35 @@ sub get_route_timestamps_p { { $ret->{$name}{rt_dep} = $ret->{$name}{sched_dep} ->clone->add( minutes => $delay->{ddelay} ); + if ( + ( + defined $delay->{adelay} + and $delay->{adelay} eq q{} + ) + or ( defined $delay->{ddelay} + and $delay->{ddelay} eq q{} ) + ) + { + $ret->{$name}{rt_bogus} = 1; + } + if ( $delay->{ddelay} and $delay->{ddelay} eq 'cancel' ) + { + $ret->{$name}{isCancelled} = 1; + } } if ( - ( - defined $delay->{adelay} - and $delay->{adelay} eq q{} - ) - or - ( defined $delay->{ddelay} and $delay->{ddelay} eq q{} ) + $station_is_past + and not $ret->{$name}{isCancelled} + and $now->epoch < ( + $ret->{$name}{rt_arr} // $ret->{$name}{rt_dep} + // $ret->{$name}{sched_arr} + // $ret->{$name}{sched_dep} // $now + )->epoch ) { - $ret->{$name}{rt_bogus} = 1; - } - if ( $delay->{ddelay} and $delay->{ddelay} eq 'cancel' ) { - $ret->{$name}{isCancelled} = 1; + $station_is_past = 0; } + $ret->{$name}{isPast} = $station_is_past; } } -- cgit v1.2.3