summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlib/Travelynx/Model/Journeys.pm32
-rw-r--r--public/static/js/travelynx-actions.js11
-rw-r--r--templates/_checked_in.html.ep3
3 files changed, 27 insertions, 19 deletions
diff --git a/lib/Travelynx/Model/Journeys.pm b/lib/Travelynx/Model/Journeys.pm
index b15507f..08b3d46 100755
--- a/lib/Travelynx/Model/Journeys.pm
+++ b/lib/Travelynx/Model/Journeys.pm
@@ -51,7 +51,7 @@ sub epoch_to_dt {
}
sub min_to_human {
- my ($minutes) = @_;
+ my ( $self, $minutes ) = @_;
my @ret;
@@ -1320,7 +1320,7 @@ sub compute_review {
$review{traveling_percentage_year}
= sprintf( "%.1f%%", $min_total * 100 / 525948.77 );
$review{traveling_percentage_year} =~ tr{.}{,};
- $review{traveling_time_year} = min_to_human($min_total);
+ $review{traveling_time_year} = $self->min_to_human($min_total);
if (@linetypes) {
$review{typical_type_1} = $linetypes[0][0];
@@ -1336,21 +1336,23 @@ sub compute_review {
$review{typical_stops_2} = [ $stops[0][0], $stops[1][0] ];
}
$review{typical_time}
- = min_to_human( $stats->{min_travel_real} / $stats->{num_trains} );
+ = $self->min_to_human( $stats->{min_travel_real} / $stats->{num_trains} );
$review{typical_km}
= sprintf( '%.0f', $stats->{km_route} / $stats->{num_trains} );
$review{typical_kmh} = sprintf( '%.0f',
$stats->{km_route} / ( $stats->{min_travel_real} / 60 ) );
$review{typical_delay_dep}
= sprintf( '%.0f', $stats->{delay_dep} / $stats->{num_trains} );
- $review{typical_delay_dep_h} = min_to_human( $review{typical_delay_dep} );
+ $review{typical_delay_dep_h}
+ = $self->min_to_human( $review{typical_delay_dep} );
$review{typical_delay_arr}
= sprintf( '%.0f', $stats->{delay_arr} / $stats->{num_trains} );
- $review{typical_delay_arr_h} = min_to_human( $review{typical_delay_arr} );
+ $review{typical_delay_arr_h}
+ = $self->min_to_human( $review{typical_delay_arr} );
if ($longest_t) {
$review{longest_t_time}
- = min_to_human( $longest_t->{rt_duration} / 60 );
+ = $self->min_to_human( $longest_t->{rt_duration} / 60 );
$review{longest_t_type} = $longest_t->{type};
$review{longest_t_lineno} = $longest_t->{line} // $longest_t->{no};
$review{longest_t_from} = $longest_t->{from_name};
@@ -1369,7 +1371,7 @@ sub compute_review {
if ($shortest_t) {
$review{shortest_t_time}
- = min_to_human( $shortest_t->{rt_duration} / 60 );
+ = $self->min_to_human( $shortest_t->{rt_duration} / 60 );
$review{shortest_t_type} = $shortest_t->{type};
$review{shortest_t_lineno} = $shortest_t->{line} // $shortest_t->{no};
$review{shortest_t_from} = $shortest_t->{from_name};
@@ -1391,9 +1393,9 @@ sub compute_review {
if ($most_delayed) {
$review{most_delayed_type} = $most_delayed->{type};
$review{most_delayed_delay_dep}
- = min_to_human( $most_delayed->{delay_dep} );
+ = $self->min_to_human( $most_delayed->{delay_dep} );
$review{most_delayed_delay_arr}
- = min_to_human( $most_delayed->{delay_arr} );
+ = $self->min_to_human( $most_delayed->{delay_arr} );
$review{most_delayed_lineno} = $most_delayed->{line}
// $most_delayed->{no};
$review{most_delayed_from} = $most_delayed->{from_name};
@@ -1406,11 +1408,11 @@ sub compute_review {
$review{most_delay_delay_dep} = $most_delay->{delay_dep};
$review{most_delay_delay_arr} = $most_delay->{delay_arr};
$review{most_delay_sched_time}
- = min_to_human( $most_delay->{sched_duration} / 60 );
+ = $self->min_to_human( $most_delay->{sched_duration} / 60 );
$review{most_delay_real_time}
- = min_to_human( $most_delay->{rt_duration} / 60 );
+ = $self->min_to_human( $most_delay->{rt_duration} / 60 );
$review{most_delay_delta}
- = min_to_human(
+ = $self->min_to_human(
( $most_delay->{rt_duration} - $most_delay->{sched_duration} )
/ 60 );
$review{most_delay_lineno} = $most_delay->{line} // $most_delay->{no};
@@ -1424,11 +1426,11 @@ sub compute_review {
$review{most_undelay_delay_dep} = $most_undelay->{delay_dep};
$review{most_undelay_delay_arr} = $most_undelay->{delay_arr};
$review{most_undelay_sched_time}
- = min_to_human( $most_undelay->{sched_duration} / 60 );
+ = $self->min_to_human( $most_undelay->{sched_duration} / 60 );
$review{most_undelay_real_time}
- = min_to_human( $most_undelay->{rt_duration} / 60 );
+ = $self->min_to_human( $most_undelay->{rt_duration} / 60 );
$review{most_undelay_delta}
- = min_to_human(
+ = $self->min_to_human(
( $most_undelay->{sched_duration} - $most_undelay->{rt_duration} )
/ 60 );
$review{most_undelay_lineno} = $most_undelay->{line}
diff --git a/public/static/js/travelynx-actions.js b/public/static/js/travelynx-actions.js
index a9e8218..91b0009 100644
--- a/public/static/js/travelynx-actions.js
+++ b/public/static/js/travelynx-actions.js
@@ -41,12 +41,19 @@ function upd_journey_data() {
});
}
function upd_countdown() {
- var now = Date.now() / 1000;
+ const now = Date.now() / 1000;
if (j_departure > now) {
$('.countdown').text('Abfahrt in ' + Math.round((j_departure - now)/60) + ' Minuten');
} else if (j_arrival > 0) {
if (j_arrival > now) {
- $('.countdown').text('Ankunft in ' + Math.round((j_arrival - now)/60) + ' Minuten');
+ var diff = Math.round((j_arrival - now)/60);
+ if (diff >= 120) {
+ $('.countdown').text('Ankunft in ' + Math.floor(diff/60) + ' Stunden und ' + (diff%60) + ' Minuten');
+ } else if (diff >= 60) {
+ $('.countdown').text('Ankunft in 1 Stunde und ' + (diff%60) + ' Minuten');
+ } else {
+ $('.countdown').text('Ankunft in ' + diff + ' Minuten');
+ }
} else {
$('.countdown').text('Ziel erreicht');
}
diff --git a/templates/_checked_in.html.ep b/templates/_checked_in.html.ep
index 472abd2..0deab37 100644
--- a/templates/_checked_in.html.ep
+++ b/templates/_checked_in.html.ep
@@ -40,8 +40,7 @@
% }
% elsif (defined $journey->{arrival_countdown}) {
% if ($journey->{arrival_countdown} > 60) {
- Ankunft in <%= sprintf('%.f', $journey->{arrival_countdown} / 60) %>
- Minute<%= sprintf('%.f', $journey->{arrival_countdown} / 60) == 1 ? '' : 'n' %>
+ Ankunft in <%= journeys->min_to_human(int($journey->{arrival_countdown} / 60)) %>
% }
% elsif ($journey->{arrival_countdown} > 0) {
Ankunft in weniger als einer Minute