Skip to content

A spy satellite simulator in your browser, except the data is real. Live open source spatial intelligence on a photorealistic 3D globe.

fix(directions): show a 59.6-second leg as 1 min, not 60 s

Rudy Celeklieb8b63fc62b0
diff --git a/changelog.d/1385-route-duration-minute.md b/changelog.d/1385-route-duration-minute.md
new file mode 100644
index 000000000..fa354766b
--- /dev/null
+++ b/changelog.d/1385-route-duration-minute.md
@@ -0,0 +1,3 @@
+- Show a route leg of 59.5 seconds or more as 1 min. The route summary and step
+ cards kept seconds below 60, then rounded 59.6 s up to "60 s"
+ (Rudy Celekli, @rudycelekli, #1385).
diff --git a/src/data/directions.test.mjs b/src/data/directions.test.mjs
index 4c9b54bd8..9426450a5 100644
--- a/src/data/directions.test.mjs
+++ b/src/data/directions.test.mjs
@@ -849,6 +849,8 @@ test('route numbers follow the page language and never break from their unit', (
assert.equal(routeDistanceText(1500), '1.5\u00a0km');
assert.equal(routeDistanceText(2_345_000), '2345\u00a0km');
assert.equal(routeDurationText(39), '39\u00a0s');
+ assert.equal(routeDurationText(59.4), '59\u00a0s');
+ assert.equal(routeDurationText(59.6), '1\u00a0min');
assert.equal(routeDurationText(3900), '1\u00a0h\u00a05\u00a0min');
assert.equal(routeDurationText(7200), '2\u00a0h');
assert.equal(routeDistanceText(-1), '');
diff --git a/src/layers/directions/index.js b/src/layers/directions/index.js
index 2b8f8875e..8fec18f65 100644
--- a/src/layers/directions/index.js
+++ b/src/layers/directions/index.js
@@ -130,7 +130,8 @@ export function routeDistanceText(meters) {
*/
export function routeDurationText(seconds) {
if (!Number.isFinite(seconds) || seconds < 0) return '';
- if (seconds < 60) return formatQuantity(Math.round(seconds), 's');
+ const wholeSeconds = Math.round(seconds);
+ if (wholeSeconds < 60) return formatQuantity(wholeSeconds, 's');
const minutes = Math.round(seconds / 60);
if (minutes < 60) return formatQuantity(minutes, 'min');
const hours = formatQuantity(Math.floor(minutes / 60), 'h');