From 760af08f4a9997f8d30ccd6b93380d0c581fbcb5 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sat, 2 Dec 2023 16:59:13 +0100 Subject: Stop, Result: Replace date/time string accessors with datetime instances --- lib/Travel/Status/DE/EFA/Result.pm | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'lib/Travel/Status/DE/EFA/Result.pm') diff --git a/lib/Travel/Status/DE/EFA/Result.pm b/lib/Travel/Status/DE/EFA/Result.pm index d23d50d..fbe0835 100644 --- a/lib/Travel/Status/DE/EFA/Result.pm +++ b/lib/Travel/Status/DE/EFA/Result.pm @@ -9,8 +9,9 @@ use parent 'Class::Accessor'; our $VERSION = '1.24'; Travel::Status::DE::EFA::Result->mk_ro_accessors( - qw(countdown date delay destination is_cancelled info key line lineref - mot occupancy operator platform platform_db platform_name sched_date sched_time time train_type train_name train_no type) + qw(countdown datetime delay destination is_cancelled info key line lineref + mot occupancy operator platform platform_db platform_name rt_datetime + sched_datetime train_type train_name train_no type) ); my @mot_mapping = qw{ @@ -31,6 +32,8 @@ sub new { $ref->{is_cancelled} = 0; } + $ref->{datetime} = $ref->{rt_datetime} // $ref->{sched_datetime}; + return bless( $ref, $obj ); } @@ -126,8 +129,8 @@ departure received by Travel::Status::DE::EFA for my $departure ($status->results) { printf( "At %s: %s to %s from platform %d\n", - $departure->time, $departure->line, $departure->destination, - $departure->platform + $departure->datetime->strftime('%H:%M'), $departure->line, + $departure->destination, $departure->platform ); } @@ -145,20 +148,19 @@ line number and destination. =head2 ACCESSORS -"Actual" in the description means that the delay (if available) is already -included in the calculation, "Scheduled" means it isn't. - =over =item $departure->countdown -Actual time in minutes from now until the tram/bus/train will depart. +Time in minutes from now until the tram/bus/train will depart, including +realtime data if available. If delay information is available, it is already included. -=item $departure->date +=item $departure->datetime -Actual departure date (DD.MM.YYYY). +DateTime(3pm) object for departure date and time. Realtime data if available, +schedule data otherwise. =item $departure->delay @@ -242,17 +244,14 @@ Each station is a Travel::Status::DE::EFA::Stop(3pm) object. List of stations the vehicle will pass after this stop. Each station is a Travel::Status::DE::EFA::Stop(3pm) object. -=item $departure->sched_date - -Scheduled departure date (DD.MM.YYYY). - -=item $departure->sched_time +=item $departure->rt_datetime -Scheduled departure time (HH:MM). +DateTime(3pm) object holding the departure date and time according to +realtime data. Undef if unknown / unavailable. -=item $departure->time +=item $departure->sched_datetime -Actual departure time (HH:MM). +DateTime(3pm) object holding the scheduled departure date and time. =item $departure->train_type -- cgit v1.2.3