summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2014-01-11 22:04:12 +0100
committerDaniel Friesel <derf@finalrewind.org>2014-01-11 22:04:12 +0100
commit5913ce8ad479c5044466550e5b0e577d4b6fb126 (patch)
tree64d2fdfb59c8a9701a907be10247616b00b2fce3
parent448293228ca7af7fa0cc5287090bfa23ac172f8a (diff)
implement --output=times option
-rwxr-xr-xbin/db-iris44
1 files changed, 41 insertions, 3 deletions
diff --git a/bin/db-iris b/bin/db-iris
index f2cd762..25ca88d 100755
--- a/bin/db-iris
+++ b/bin/db-iris
@@ -2,6 +2,7 @@
use strict;
use warnings;
use 5.018;
+use utf8;
no if $] >= 5.018, warnings => 'experimental::smartmatch';
@@ -144,8 +145,34 @@ sub display_result {
@{$line}[ 0 .. 4 ]
);
+ my $d = $line->[5];
+ my $need_newlines = 0;
+
+ if ( $edata{times} ) {
+ if ( not defined $d->delay ) {
+ print "\n";
+ }
+ elsif ( $d->delay == 0 ) {
+ printf( "%s+0\n", q{ } x 15 );
+ }
+ else {
+ printf(
+ "%5s → %5s %+d\n",
+ $d->arrival ? $d->arrival->strftime('%H:%M') : q{},
+ $d->departure ? $d->departure->strftime('%H:%M') : q{},
+ $d->delay,
+ );
+ }
+
+ }
+
if ( $edata{route} ) {
- print "\n" . join( "\n", $line->[5]->route ) . "\n\n\n";
+ $need_newlines = 1;
+ print "\n" . join( "\n", $d->route );
+ }
+
+ if ($need_newlines) {
+ print "\n\n";
}
}
@@ -180,11 +207,22 @@ for my $d ( $status->results() ) {
$delay = ' CANCELED';
}
+ my $timestr;
+ if ( $edata{times} ) {
+ $timestr = sprintf( '%5s → %5s',
+ $d->sched_arrival ? $d->sched_arrival->strftime('%H:%M') : q{},
+ $d->sched_departure ? $d->sched_departure->strftime('%H:%M') : q{},
+ );
+ }
+ else {
+ $timestr = $d->time . $delay;
+ }
+
push(
@output,
[
- $d->time . $delay,
- $d->train, $arrivals ? q{} : join( q{ }, $d->route_interesting ),
+ $timestr, $d->train,
+ $arrivals ? q{} : join( q{ }, $d->route_interesting ),
$d->route_end, $d->platform, $d
]
);