fix: prevent rounding error show 60s

This commit is contained in:
Carlos Valente
2025-11-02 15:17:26 +01:00
committed by Carlos Valente
parent 5dce1a40bc
commit 9f2db10548
2 changed files with 25 additions and 2 deletions
+7 -1
View File
@@ -117,6 +117,7 @@ export function formatDuration(duration: number, hideSeconds = true): string {
const hours = Math.floor(duration / MILLIS_PER_HOUR);
const minutes = Math.floor((duration % MILLIS_PER_HOUR) / MILLIS_PER_MINUTE);
let result = '';
if (hours > 0) {
result += `${hours}h`;
@@ -126,11 +127,16 @@ export function formatDuration(duration: number, hideSeconds = true): string {
}
if (!hideSeconds) {
const seconds = Math.ceil((duration % MILLIS_PER_MINUTE) / MILLIS_PER_SECOND);
const remainingMs = duration % MILLIS_PER_MINUTE;
const exactSeconds = remainingMs / MILLIS_PER_SECOND;
// cap at 59 to avoid showing 60s
const seconds = Math.min(59, Math.ceil(exactSeconds));
if (seconds > 0) {
result += `${seconds}s`;
}
}
return result;
}