Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apps/web/__tests__/unit/clock-hours.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ describe("formatClockWithHundredths", () => {
expect(formatClockWithHundredths(3600)).toBe("1:00:00.00");
expect(formatClockWithHundredths(3905.5)).toBe("1:05:05.50");
});

it("carries a rounded-up minute instead of printing :60.00", () => {
expect(formatClockWithHundredths(59.994)).toBe("00:59.99");
expect(formatClockWithHundredths(59.996)).toBe("01:00.00");
expect(formatClockWithHundredths(119.999)).toBe("02:00.00");
expect(formatClockWithHundredths(3599.999)).toBe("1:00:00.00");
});
});

describe("Slack previews", () => {
Expand Down
4 changes: 3 additions & 1 deletion apps/web/lib/player-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export function formatClock(seconds: number): string {
}

export function formatClockWithHundredths(seconds: number): string {
const safe = Math.max(0, seconds);
// Round before splitting so 59.996 carries into the next minute instead of
// printing as 00:60.00.
const safe = Number(Math.max(0, seconds).toFixed(2));
const hours = Math.floor(safe / 3600);
const minutes = Math.floor((safe - hours * 3600) / 60);
const remainingSeconds = safe - hours * 3600 - minutes * 60;
Expand Down
Loading