From db7869656bff9430f21059a6fbb6ad956e038ddc Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Tue, 8 Oct 2024 21:08:59 +0200 Subject: Stop: Calculate rt_{arr,dep} if needed --- lib/Travel/Status/DE/EFA/Stop.pm | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'lib/Travel') diff --git a/lib/Travel/Status/DE/EFA/Stop.pm b/lib/Travel/Status/DE/EFA/Stop.pm index e760713..af55ee3 100644 --- a/lib/Travel/Status/DE/EFA/Stop.pm +++ b/lib/Travel/Status/DE/EFA/Stop.pm @@ -21,16 +21,32 @@ sub new { my $ref = \%conf; + if ( $ref->{sched_arr} and $ref->{arr_delay} and not $ref->{rt_arr} ) { + $ref->{rt_arr} + = $ref->{sched_arr}->clone->add( minutes => $ref->{arr_delay} ); + } + + if ( $ref->{sched_dep} and $ref->{dep_delay} and not $ref->{rt_dep} ) { + $ref->{rt_dep} + = $ref->{sched_dep}->clone->add( minutes => $ref->{dep_delay} ); + } + $ref->{arr} //= $ref->{rt_arr} // $ref->{sched_arr}; $ref->{dep} //= $ref->{rt_dep} // $ref->{sched_dep}; - if ( $ref->{rt_arr} and $ref->{sched_arr} ) { + if ( $ref->{rt_arr} + and $ref->{sched_arr} + and not defined $ref->{arr_delay} ) + { $ref->{arr_delay} = $ref->{rt_arr}->subtract_datetime( $ref->{sched_arr} ) ->in_units('minutes'); } - if ( $ref->{rt_dep} and $ref->{sched_dep} ) { + if ( $ref->{rt_dep} + and $ref->{sched_dep} + and not defined $ref->{dep_delay} ) + { $ref->{dep_delay} = $ref->{rt_dep}->subtract_datetime( $ref->{sched_dep} ) ->in_units('minutes'); -- cgit v1.2.3