From 2c2d4966b285d335579379a9bb97423234155f19 Mon Sep 17 00:00:00 2001 From: Christophe Vila Date: Sun, 19 Jul 2026 16:55:11 +0200 Subject: [PATCH] Fix pace/elapsed-time formatting rounding 59.6s up to ":60" instead of carrying over formatPaceShort and formatElapsed each floored the minutes and rounded the leftover seconds independently, so e.g. 419.6 sec/km displayed as "6:60/km" instead of "7:00/km". Both now round the total seconds once, then split into minutes/seconds from that rounded value. --- .../charts/ExpectedVsActualChart.tsx | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/charts/ExpectedVsActualChart.tsx b/frontend/src/components/charts/ExpectedVsActualChart.tsx index d962cc4..7900b39 100644 --- a/frontend/src/components/charts/ExpectedVsActualChart.tsx +++ b/frontend/src/components/charts/ExpectedVsActualChart.tsx @@ -14,20 +14,27 @@ function paceSecPerKm(mps: number | null): number | null { return pace <= MAX_PLAUSIBLE_PACE_SEC_PER_KM ? pace : null; } -function formatPaceShort(secPerKm: number): string { - const m = Math.floor(secPerKm / 60); - const s = Math.round(secPerKm % 60); +// Rounds the total seconds first, then splits into minutes/seconds -- doing +// it the other way around (floor the minutes, round the leftover seconds +// separately) can round 59.6s up to "60", displaying e.g. "6:60" instead of +// carrying over to "7:00". +function formatMinutesSeconds(totalSeconds: number): string { + const total = Math.round(totalSeconds); + const m = Math.floor(total / 60); + const s = total % 60; return `${m}:${s.toString().padStart(2, "0")}`; } +function formatPaceShort(secPerKm: number): string { + return formatMinutesSeconds(secPerKm); +} + function formatPace(secPerKm: number): string { return `${formatPaceShort(secPerKm)}/km`; } function formatElapsed(minutes: number): string { - const m = Math.floor(minutes); - const s = Math.round((minutes - m) * 60); - return `${m}:${s.toString().padStart(2, "0")}`; + return formatMinutesSeconds(minutes * 60); } function percentile(sortedAsc: number[], p: number): number {