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 {