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): avoid overflow in time rounding

Arham Waniac336ebbc048
diff --git a/src/lib/ai-edition/timeline/format.test.ts b/src/lib/ai-edition/timeline/format.test.ts
index c242d2e98..7ffb33fba 100644
--- a/src/lib/ai-edition/timeline/format.test.ts
+++ b/src/lib/ai-edition/timeline/format.test.ts
@@ -20,6 +20,10 @@ describe("formatSec", () => {
it("carries rounded seconds into the next minute", () => {
expect(formatSec(59.96)).toBe("1:00.0");
});
+
+ it("keeps finite durations finite while rounding", () => {
+ expect(formatSec(Number.MAX_VALUE)).not.toMatch(/Infinity|NaN/);
+ });
});
describe("formatSeconds", () => {
@@ -37,6 +41,10 @@ describe("formatSeconds", () => {
it("carries rounded seconds into the next hour", () => {
expect(formatSeconds(3599.96)).toBe("1:00:00.0");
});
+
+ it("keeps finite durations finite while rounding", () => {
+ expect(formatSeconds(Number.MAX_VALUE)).not.toMatch(/Infinity|NaN/);
+ });
});
describe("formatMs", () => {
diff --git a/src/lib/ai-edition/timeline/format.ts b/src/lib/ai-edition/timeline/format.ts
index d15955853..b35069a0e 100644
--- a/src/lib/ai-edition/timeline/format.ts
+++ b/src/lib/ai-edition/timeline/format.ts
@@ -12,11 +12,13 @@
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,
- };
+ let totalMinutes = Math.floor(safe / 60);
+ let seconds = Math.round((safe % 60) * 10) / 10;
+ if (seconds >= 60) {
+ totalMinutes += 1;
+ seconds = 0;
+ }
+ return { totalMinutes, seconds };
}
/** `m:ss.t` — no hour field, ever. */