summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2023-11-17 22:06:10 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2023-11-17 22:06:10 +0100
commitd967aecfde117a4d09053cbddb155a3bad893829 (patch)
treecece69d9925cd2f08b7b7fe7760bee80c8a31be3
parent45ebbfae7b17d829c0da49982e059171e15463cb (diff)
check for (probably) impossible connections with negative transfer duration
-rwxr-xr-xbin/hafas34
1 files changed, 25 insertions, 9 deletions
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
);
}