summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2023-09-16 22:23:44 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2023-09-16 22:23:44 +0200
commit04c8d7672ac977257379c62be1833d3b3b8e8e7b (patch)
tree69935a74a0dde0c00b684b3a22b090ab50a62d96
parent434eb5a18dc51d6c9cf7de67fcff216a3f9a8b57 (diff)
journey: show distances below 10km with 100m resolution (and <1km with 1m)
-rwxr-xr-xlib/Travelynx.pm14
-rw-r--r--templates/journey.html.ep4
2 files changed, 16 insertions, 2 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm
index b08593f..0f7b289 100755
--- a/lib/Travelynx.pm
+++ b/lib/Travelynx.pm
@@ -394,6 +394,20 @@ sub startup {
);
$self->helper(
+ 'sprintf_km' => sub {
+ my ( $self, $km ) = @_;
+
+ if ( $km < 1 ) {
+ return sprintf( '%.f m', $km * 1000 );
+ }
+ if ( $km < 10 ) {
+ return sprintf( '%.1f km', $km );
+ }
+ return sprintf( '%.f km', $km );
+ }
+ );
+
+ $self->helper(
'load_icon' => sub {
my ( $self, $load ) = @_;
my $first = $load->{FIRST} // 0;
diff --git a/templates/journey.html.ep b/templates/journey.html.ep
index d138126..f5eebfc 100644
--- a/templates/journey.html.ep
+++ b/templates/journey.html.ep
@@ -130,8 +130,8 @@
<%= numify_skipped_stations($journey->{skip_route}) %><br/>
% }
% if ($journey->{km_route} > 0.1) {
- ca. <%= sprintf('%.f', $journey->{km_route}) %> km
- (Luftlinie: <%= sprintf('%.f', $journey->{km_beeline}) %> km)
+ ca. <%= sprintf_km($journey->{km_route}) %>
+ (Luftlinie: <%= sprintf_km($journey->{km_beeline}) %>)
% }
% else {
?