Skip to content
Open
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
9 changes: 9 additions & 0 deletions src/components/video-editor/timeline/core/time.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ describe("timeline core/time", () => {
expect(formatPlayheadTime(61_400)).toBe("1:01.4");
});

it("rolls seconds into the next minute when rounding reaches 60", () => {
// 59.95s–59.99s round up to 60.0s and must carry into the minute
// instead of rendering "60.0s" or "1:60.0".
expect(formatPlayheadTime(59_950)).toBe("1:00.0");
expect(formatPlayheadTime(59_970)).toBe("1:00.0");
expect(formatPlayheadTime(119_970)).toBe("2:00.0");
expect(formatPlayheadTime(0)).toBe("0.0s");
});

it("normalizes wheel delta by deltaMode", () => {
expect(normalizeWheelDeltaToPixels(2, 0)).toBe(2);
expect(normalizeWheelDeltaToPixels(2, 1)).toBe(32);
Expand Down
10 changes: 7 additions & 3 deletions src/components/video-editor/timeline/core/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,13 @@ export function formatTimeLabel(milliseconds: number, intervalMs: number) {
}

export function formatPlayheadTime(ms: number): string {
const s = ms / 1000;
const min = Math.floor(s / 60);
const sec = s % 60;
// Round to the displayed precision (tenths of a second) before splitting
// into minutes and seconds. Rounding the seconds component on its own lets
// values such as 59.97s render as "60.0" and carry into labels like
// "1:60.0" or "60.0s" instead of rolling over to the next minute.
const tenths = Math.round((ms / 1000) * 10);
const min = Math.floor(tenths / 600);
const sec = (tenths - min * 600) / 10;
if (min > 0) return `${min}:${sec.toFixed(1).padStart(4, "0")}`;
return `${sec.toFixed(1)}s`;
}