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.
This commit is contained in:
2026-07-19 16:55:11 +02:00
parent 82f08c0c1e
commit 2c2d4966b2

View File

@@ -14,20 +14,27 @@ function paceSecPerKm(mps: number | null): number | null {
return pace <= MAX_PLAUSIBLE_PACE_SEC_PER_KM ? pace : null; return pace <= MAX_PLAUSIBLE_PACE_SEC_PER_KM ? pace : null;
} }
function formatPaceShort(secPerKm: number): string { // Rounds the total seconds first, then splits into minutes/seconds -- doing
const m = Math.floor(secPerKm / 60); // it the other way around (floor the minutes, round the leftover seconds
const s = Math.round(secPerKm % 60); // 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")}`; return `${m}:${s.toString().padStart(2, "0")}`;
} }
function formatPaceShort(secPerKm: number): string {
return formatMinutesSeconds(secPerKm);
}
function formatPace(secPerKm: number): string { function formatPace(secPerKm: number): string {
return `${formatPaceShort(secPerKm)}/km`; return `${formatPaceShort(secPerKm)}/km`;
} }
function formatElapsed(minutes: number): string { function formatElapsed(minutes: number): string {
const m = Math.floor(minutes); return formatMinutesSeconds(minutes * 60);
const s = Math.round((minutes - m) * 60);
return `${m}:${s.toString().padStart(2, "0")}`;
} }
function percentile(sortedAsc: number[], p: number): number { function percentile(sortedAsc: number[], p: number): number {