From d967aecfde117a4d09053cbddb155a3bad893829 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Fri, 17 Nov 2023 22:06:10 +0100 Subject: check for (probably) impossible connections with negative transfer duration --- bin/hafas | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'bin/hafas') diff --git a/bin/hafas b/bin/hafas index e992708..2bd5061 100755 --- a/bin/hafas +++ b/bin/hafas @@ -283,31 +283,47 @@ for my $res ( $hafas->connections ) { } } + my $negative_transfer; + my $glance = q{}; for my $sec ( $res->sections ) { if ( $sec->type ne 'JNY' ) { next; } if ( defined $sec->transfer_duration ) { - $glance .= sprintf( - ' (%01d:%02d) %s', - $sec->transfer_duration->in_units( 'hours', 'minutes' ), - $sec->name - ); + if ( $sec->transfer_duration->in_units('minutes') >= 0 ) { + $glance .= sprintf( + ' (%01d:%02d) "%s"', + $sec->transfer_duration->in_units( 'hours', 'minutes' ), + $sec->name + ); + } + else { + $negative_transfer = 1; + $glance .= sprintf( ' (--:--) %s', $sec->name ); + } } else { $glance .= $sec->name; } } - if ($cancelled) { - printf( "--:-- %s %s\n", display_occupancies( $res->load ), $glance ); + if ( $cancelled or $negative_transfer ) { + printf( + "--:-- (%02d:%02d) %s %s %s\n", + $res->duration->in_units( 'hours', 'minutes' ), + $res->arr->strftime('%H:%M'), + display_occupancies( $res->load ), $glance + ); } else { printf( - "%02d:%02d %s %s\n", + "%s (%02d:%02d) %s %s %s\n", + $res->dep->strftime('%H:%M'), $res->duration->in_units( 'hours', 'minutes' ), - display_occupancies( $res->load ), $glance + $res->arr->strftime('%H:%M'), + display_occupancies( $res->load ), + $glance ); } -- cgit v1.2.3