summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2014-01-07 20:01:28 +0100
committerDaniel Friesel <derf@finalrewind.org>2014-01-07 20:01:28 +0100
commita99466f6b08f20d38b9de285223304e4b71f8fe4 (patch)
treef59252fa1fae7f2522d5b8f9fb9dbb06a6d59348
parent117c4d98c2f3d763358e922c05f3d9dc1ded6ad5 (diff)
very limited date/time support (IRIS does not provide much past/future data)
-rwxr-xr-xbin/db-iris26
-rw-r--r--lib/Travel/Status/DE/IRIS.pm7
2 files changed, 25 insertions, 8 deletions
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 {
diff --git a/lib/Travel/Status/DE/IRIS.pm b/lib/Travel/Status/DE/IRIS.pm
index 6cec7d7..e6bccaf 100644
--- a/lib/Travel/Status/DE/IRIS.pm
+++ b/lib/Travel/Status/DE/IRIS.pm
@@ -26,7 +26,8 @@ sub new {
}
my $self = {
- dt_now => DateTime->now( time_zone => 'Europe/Berlin' ),
+ datetime => $opt{datetime}
+ // DateTime->now( time_zone => 'Europe/Berlin' ),
station => $opt{station},
user_agent => $ua,
};
@@ -47,7 +48,7 @@ sub new {
$self->{nodes}{station} = ( $xml_st->findnodes('//station') )[0];
- my $dt_req = $self->{dt_now}->clone;
+ my $dt_req = $self->{datetime}->clone;
for ( 1 .. 3 ) {
$self->get_timetable( $self->{nodes}{station}->getAttribute('eva'),
$dt_req );
@@ -231,7 +232,7 @@ sub errstr {
sub results {
my ($self) = @_;
- return @{ $self->{results} };
+ return @{ $self->{results} // [] };
}
1;