summaryrefslogtreecommitdiff
path: root/lib/DBInfoscreen
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2021-07-26 22:23:30 +0200
committerDaniel Friesel <derf@finalrewind.org>2021-07-26 22:23:30 +0200
commit3fd12f84c507d8b968e7ed652f79e43301fbe0e0 (patch)
tree7e2367319e8247e7ae8d229f5dd0ebb37f65d61f /lib/DBInfoscreen
parent7fa4f47bcd76ef4184e1cbf12ca53db73c8e2791 (diff)
train details/route: indicate whether a stop is past or future4.5.0
Diffstat (limited to 'lib/DBInfoscreen')
-rw-r--r--lib/DBInfoscreen/Helper/HAFAS.pm38
1 files changed, 27 insertions, 11 deletions
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;
}
}