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(usage): treat an unrepresentable birthtime as an unknown install week

EtienneLescot17a04f113693
diff --git a/electron/usage-ping.test.ts b/electron/usage-ping.test.ts
index 91cfb73e0..f59d4d30d 100644
--- a/electron/usage-ping.test.ts
+++ b/electron/usage-ping.test.ts
@@ -137,8 +137,14 @@ describe("install week", () => {
it("dates the install by the userData directory's birthtime, never its mtime", () => {
expect(installWeekFrom({ birthtimeMs: Date.parse("2025-05-07T12:00:00Z") })).toBe("2025-W19");
// Filesystems that record no birthtime report 0; mtime would move, so no fallback.
- expect(installWeekFrom({ birthtimeMs: 0 })).toBe("unknown");
- expect(installWeekFrom({ birthtimeMs: Number.NaN })).toBe("unknown");
+ const mtimeMs = Date.parse("2025-05-07T12:00:00Z");
+ for (const birthtimeMs of [0, Number.NaN]) {
+ const stats = { birthtimeMs, mtimeMs };
+ expect(installWeekFrom(stats)).toBe("unknown");
+ }
+ // Positive but past the last representable Date.
+ expect(installWeekFrom({ birthtimeMs: 8.64e15 + 1 })).toBe("unknown");
+ expect(installWeekFrom({ birthtimeMs: Number.POSITIVE_INFINITY })).toBe("unknown");
expect(installWeekFrom(null)).toBe("unknown");
});
diff --git a/electron/usage-ping.ts b/electron/usage-ping.ts
index 0349caeae..94f991870 100644
--- a/electron/usage-ping.ts
+++ b/electron/usage-ping.ts
@@ -81,8 +81,9 @@ export function periodKeys(now: Date): { day: string; week: string; month: strin
* no birthtime (0), the week is "unknown": mtime moves whenever the folder changes, and the
* week is kept for good once sent. */
export function installWeekFrom(stats: { birthtimeMs: number } | null): string {
- const ms = stats?.birthtimeMs;
- return ms && ms > 0 ? periodKeys(new Date(ms)).week : "unknown";
+ const date = new Date(stats?.birthtimeMs ?? 0);
+ // Beyond ±8.64e15 ms a Date is invalid, and toISOString would throw outside any try.
+ return date.getTime() > 0 ? periodKeys(date).week : "unknown";
}
/** "2026-W44" (weeks 01 to 53) or "unknown"; anything else is re-derived. */