From dfd50dae2fd80ca7d1f9bf6892067fba93571ed2 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 7 May 2020 22:12:33 +0200 Subject: Result: Report real time by default Scheduled time is now available via sched_* accessors --- lib/Travel/Status/DE/HAFAS.pm | 24 ++++++++++++------------ lib/Travel/Status/DE/HAFAS/Result.pm | 19 +++++++++++++++++-- 2 files changed, 29 insertions(+), 14 deletions(-) (limited to 'lib/Travel/Status/DE') diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm index 0dccb99..16c879e 100644 --- a/lib/Travel/Status/DE/HAFAS.pm +++ b/lib/Travel/Status/DE/HAFAS.pm @@ -348,18 +348,18 @@ sub results { push( @{ $self->{results} }, Travel::Status::DE::HAFAS::Result->new( - date => $date, - datetime => $datetime, - datetime_now => $self->{datetime_now}, - raw_delay => $delay, - raw_e_delay => $e_delay, - messages => \@messages, - time => $time, - train => $train, - route_end => $dest, - platform => $platform, - new_platform => $new_platform, - info => $info, + sched_date => $date, + sched_datetime => $datetime, + datetime_now => $self->{datetime_now}, + raw_delay => $delay, + raw_e_delay => $e_delay, + messages => \@messages, + sched_time => $time, + train => $train, + route_end => $dest, + platform => $platform, + new_platform => $new_platform, + info => $info, ) ); } diff --git a/lib/Travel/Status/DE/HAFAS/Result.pm b/lib/Travel/Status/DE/HAFAS/Result.pm index 2950736..e5c81c0 100644 --- a/lib/Travel/Status/DE/HAFAS/Result.pm +++ b/lib/Travel/Status/DE/HAFAS/Result.pm @@ -11,14 +11,29 @@ use parent 'Class::Accessor'; our $VERSION = '2.05'; Travel::Status::DE::HAFAS::Result->mk_ro_accessors( - qw(date datetime info raw_e_delay raw_delay time train route_end)); + qw(sched_date date sched_datetime datetime info raw_e_delay raw_delay + sched_time time train route_end) +); sub new { my ( $obj, %conf ) = @_; my $ref = \%conf; + bless( $ref, $obj ); - return bless( $ref, $obj ); + if ( my $delay = $ref->delay ) { + $ref->{datetime} + = $ref->{sched_datetime}->clone->add( minutes => $delay ); + $ref->{date} = $ref->{datetime}->strftime('%d.%m.%Y'); + $ref->{time} = $ref->{datetime}->strftime('%H:%M'); + } + else { + $ref->{datetime} = $ref->{sched_datetime}; + $ref->{date} = $ref->{sched_date}; + $ref->{time} = $ref->{sched_time}; + } + + return $ref; } sub countdown { -- cgit v1.2.3