From a99466f6b08f20d38b9de285223304e4b71f8fe4 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 7 Jan 2014 20:01:28 +0100 Subject: very limited date/time support (IRIS does not provide much past/future data) --- bin/db-iris | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'bin') diff --git a/bin/db-iris b/bin/db-iris index 5db30e1..f9aeccb 100755 --- a/bin/db-iris +++ b/bin/db-iris @@ -5,6 +5,8 @@ use 5.018; our $VERSION = '0.00'; +use DateTime; +use DateTime::Format::Strptime; use Encode qw(decode); use Getopt::Long qw(:config no_ignore_case); use List::Util qw(max); @@ -14,6 +16,7 @@ use Travel::Status::DE::IRIS::Stations; my %train_type; my ( $date, $time ); +my $datetime = DateTime->now( time_zone => 'Europe/Berlin' ); my $arrivals = 0; my $filter_via; my $ignore_late = 0; @@ -58,13 +61,26 @@ for my $type ( split( qr{,}, $types ) ) { } } +if ($date) { + my ( $day, $month, $year ) = split( /\./, $date ); + $datetime->set( + day => $day, + month => $month, + year => $year || $datetime->year, + ); +} +if ($time) { + my ( $hour, $minute, $second ) = split( /:/, $time ); + $datetime->set( + hour => $hour, + minute => $minute, + second => $second || $datetime->second, + ); +} + my $status = Travel::Status::DE::IRIS->new( - date => $date, - language => $language, - mot => \%train_type, + datetime => $datetime, station => $station, - time => $time, - mode => $arrivals ? 'arr' : 'dep', ); sub get_station { -- cgit v1.2.3