summaryrefslogtreecommitdiff
path: root/lib/Travel/Status/DE/IRIS
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2017-07-02 18:37:50 +0200
committerDaniel Friesel <derf@finalrewind.org>2017-07-02 18:37:50 +0200
commit4aee2fb6dc0755371eaa23459e514ac76f6a9576 (patch)
treeef02ed2d9e931957d5567d73febc0b511f69e4fa /lib/Travel/Status/DE/IRIS
parent710c15968ef20e0c17a9ce0cd493596f6a457cde (diff)
Fix delay calculation for prematurely terminating trains
Diffstat (limited to 'lib/Travel/Status/DE/IRIS')
-rw-r--r--lib/Travel/Status/DE/IRIS/Result.pm62
1 files changed, 33 insertions, 29 deletions
diff --git a/lib/Travel/Status/DE/IRIS/Result.pm b/lib/Travel/Status/DE/IRIS/Result.pm
index 3de6400..07d1bf9 100644
--- a/lib/Travel/Status/DE/IRIS/Result.pm
+++ b/lib/Travel/Status/DE/IRIS/Result.pm
@@ -233,6 +233,17 @@ sub parse_ts {
sub set_ar {
my ( $self, %attrib ) = @_;
+ if ( $attrib{status} and $attrib{status} eq 'c' ) {
+ $self->{arrival_is_cancelled} = 1;
+ }
+ elsif ( $attrib{status} and $attrib{status} eq 'a' ) {
+ $self->{arrival_is_additional} = 1;
+ }
+ else {
+ $self->{arrival_is_additional} = 0;
+ $self->{arrival_is_cancelled} = 0;
+ }
+
# unscheduled arrivals may not appear in the plan, but we do need to
# know their planned arrival time
if ( $attrib{plan_arrival_ts} ) {
@@ -242,13 +253,15 @@ sub set_ar {
if ( $attrib{arrival_ts} ) {
$self->{arrival} = $self->parse_ts( $attrib{arrival_ts} );
- $self->{delay}
- = $self->arrival->subtract_datetime( $self->sched_arrival )
- ->in_units('minutes');
+ if ( not $self->{arrival_is_cancelled} ) {
+ $self->{delay}
+ = $self->arrival->subtract_datetime( $self->sched_arrival )
+ ->in_units('minutes');
+ }
}
else {
$self->{arrival} = $self->{sched_arrival};
- $self->{delay} = 0;
+ $self->{delay} //= 0;
}
if ( $attrib{platform} ) {
@@ -274,23 +287,23 @@ sub set_ar {
$self->{sched_route_start} = $self->{sched_route_pre}[0];
}
+ return $self;
+}
+
+sub set_dp {
+ my ( $self, %attrib ) = @_;
+
if ( $attrib{status} and $attrib{status} eq 'c' ) {
- $self->{arrival_is_cancelled} = 1;
+ $self->{departure_is_cancelled} = 1;
}
elsif ( $attrib{status} and $attrib{status} eq 'a' ) {
- $self->{arrival_is_additional} = 1;
+ $self->{departure_is_additional} = 1;
}
else {
- $self->{arrival_is_additional} = 0;
- $self->{arrival_is_cancelled} = 0;
+ $self->{departure_is_additional} = 0;
+ $self->{departure_is_cancelled} = 0;
}
- return $self;
-}
-
-sub set_dp {
- my ( $self, %attrib ) = @_;
-
# unscheduled arrivals may not appear in the plan, but we do need to
# know their planned arrival time
if ( $attrib{plan_departure_ts} ) {
@@ -300,13 +313,15 @@ sub set_dp {
if ( $attrib{departure_ts} ) {
$self->{departure} = $self->parse_ts( $attrib{departure_ts} );
- $self->{delay}
- = $self->departure->subtract_datetime( $self->sched_departure )
- ->in_units('minutes');
+ if ( not $self->{departure_is_cancelled} ) {
+ $self->{delay}
+ = $self->departure->subtract_datetime( $self->sched_departure )
+ ->in_units('minutes');
+ }
}
else {
$self->{departure} = $self->{sched_departure};
- $self->{delay} = 0;
+ $self->{delay} //= 0;
}
if ( $attrib{platform} ) {
@@ -332,17 +347,6 @@ sub set_dp {
$self->{sched_route_end} = $self->{sched_route_post}[-1];
}
- if ( $attrib{status} and $attrib{status} eq 'c' ) {
- $self->{departure_is_cancelled} = 1;
- }
- elsif ( $attrib{status} and $attrib{status} eq 'a' ) {
- $self->{departure_is_additional} = 1;
- }
- else {
- $self->{departure_is_additional} = 0;
- $self->{departure_is_cancelled} = 0;
- }
-
return $self;
}