Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(timeline): carry rounded timecode seconds

Arham Wani5aafe6c5320e
diff --git a/src/lib/ai-edition/timeline/format.test.ts b/src/lib/ai-edition/timeline/format.test.ts
index f7f2bd67e..c242d2e98 100644
--- a/src/lib/ai-edition/timeline/format.test.ts
+++ b/src/lib/ai-edition/timeline/format.test.ts
@@ -16,6 +16,10 @@ describe("formatSec", () => {
expect(formatSec(Number.NaN)).toBe("0:00.0");
expect(formatSec(Number.POSITIVE_INFINITY)).toBe("0:00.0");
});
+
+ it("carries rounded seconds into the next minute", () => {
+ expect(formatSec(59.96)).toBe("1:00.0");
+ });
});
describe("formatSeconds", () => {
@@ -29,6 +33,10 @@ describe("formatSeconds", () => {
expect(formatSeconds(-1)).toBe("0:00.0");
expect(formatSeconds(Number.NaN)).toBe("0:00.0");
});
+
+ it("carries rounded seconds into the next hour", () => {
+ expect(formatSeconds(3599.96)).toBe("1:00:00.0");
+ });
});
describe("formatMs", () => {
@@ -37,4 +45,8 @@ describe("formatMs", () => {
expect(formatMs(-1)).toBe("0:00.0");
expect(formatMs(Number.NaN)).toBe("0:00.0");
});
+
+ it("inherits minute carry from formatSec", () => {
+ expect(formatMs(59_960)).toBe("1:00.0");
+ });
});
diff --git a/src/lib/ai-edition/timeline/format.ts b/src/lib/ai-edition/timeline/format.ts
index a9d1ff301..d15955853 100644
--- a/src/lib/ai-edition/timeline/format.ts
+++ b/src/lib/ai-edition/timeline/format.ts
@@ -10,20 +10,26 @@
// padded hours, no tenths) and timeUtils' `formatTimePadded` (mm:ss) are
// different formats, not copies of these.
+function splitRoundedTime(value: number): { totalMinutes: number; seconds: number } {
+ const safe = Number.isFinite(value) && value > 0 ? value : 0;
+ const totalTenths = Math.round(safe * 10);
+ return {
+ totalMinutes: Math.floor(totalTenths / 600),
+ seconds: (totalTenths % 600) / 10,
+ };
+}
+
/** `m:ss.t` — no hour field, ever. */
export function formatSec(sec: number): string {
- const safe = Number.isFinite(sec) && sec > 0 ? sec : 0;
- const m = Math.floor(safe / 60);
- const s = (safe % 60).toFixed(1);
- return `${m}:${s.padStart(4, "0")}`;
+ const { totalMinutes, seconds } = splitRoundedTime(sec);
+ return `${totalMinutes}:${seconds.toFixed(1).padStart(4, "0")}`;
}
/** `m:ss.t`, or `h:mm:ss.t` once past an hour. */
export function formatSeconds(value: number): string {
- const safe = Number.isFinite(value) && value > 0 ? value : 0;
- const hours = Math.floor(safe / 3600);
- const minutes = Math.floor((safe % 3600) / 60);
- const seconds = safe % 60;
+ const { totalMinutes, seconds } = splitRoundedTime(value);
+ const hours = Math.floor(totalMinutes / 60);
+ const minutes = totalMinutes % 60;
if (hours > 0) {
return `${hours}:${String(minutes).padStart(2, "0")}:${seconds.toFixed(1).padStart(4, "0")}`;
}