summaryrefslogtreecommitdiff
path: root/lib/Travel/Status/DE/HAFAS.pm
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2015-12-21 18:45:58 +0100
committerDaniel Friesel <derf@finalrewind.org>2015-12-21 18:45:58 +0100
commit702918a5e19153c1de8af669743eed8bb46f3487 (patch)
treefbcc41f787004f6d46a9e635796aa19d72a3e41e /lib/Travel/Status/DE/HAFAS.pm
parent1737099d4b5629903eaea16e367980dffa80d281 (diff)
Result: Add ->datetime, ->countdown and ->countdown_sec accessors
Diffstat (limited to 'lib/Travel/Status/DE/HAFAS.pm')
-rw-r--r--lib/Travel/Status/DE/HAFAS.pm14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm
index 55c79df..a0535c3 100644
--- a/lib/Travel/Status/DE/HAFAS.pm
+++ b/lib/Travel/Status/DE/HAFAS.pm
@@ -8,6 +8,8 @@ use utf8;
no if $] >= 5.018, warnings => 'experimental::smartmatch';
use Carp qw(confess);
+use DateTime;
+use DateTime::Format::Strptime;
use LWP::UserAgent;
use POSIX qw(strftime);
use Travel::Status::DE::HAFAS::Result;
@@ -291,6 +293,14 @@ sub results {
$self->{results} = [];
+ $self->{datetime_now} //= DateTime->now(
+ time_zone => 'Europe/Berlin',
+ );
+ $self->{strptime_obj} //= DateTime::Format::Strptime->new(
+ pattern => '%d.%m.%YT%H:%M',
+ time_zone => 'Europe/Berlin',
+ );
+
for my $tr ( @{ $self->{tree}->findnodes($xp_element) } ) {
my @message_nodes = $tr->findnodes($xp_msg);
@@ -328,10 +338,14 @@ sub results {
$train =~ s{#.*$}{};
+ my $datetime = $self->{strptime_obj}->parse_datetime("${date}T${time}");
+
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,