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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user