From c931a5561661051a6bcf0e54f180f2f5a727dd28 Mon Sep 17 00:00:00 2001 From: Big Onion Date: Sun, 26 Jul 2026 12:33:03 -0400 Subject: [PATCH] fix: keep .skf ZIP mtime within DOS date range in all timezones The .skf writer pinned the ZIP entry mtime to a UTC-based epoch (new Date("1980-01-01T00:00:00.000Z")). fflate encodes ZIP mtimes as DOS dates using local-time getters and rejects years outside 1980-2099. In any timezone west of UTC that instant is 1979-12-31 locally, so exporting or saving a project (e.g. Save to shared) threw "date not in range 1980-2099". Build the pinned epoch from local components (new Date(1980, 0, 1)) so the year is always 1980 regardless of timezone. Add a regression test that exports under Etc/GMT+12 and round-trips the project. Co-Authored-By: Claude Opus 4.8 --- apps/web/src/lib/skfProject.ts | 6 +++++- tests/unit/skfProject.test.ts | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/apps/web/src/lib/skfProject.ts b/apps/web/src/lib/skfProject.ts index 4a85c3c..447dd54 100644 --- a/apps/web/src/lib/skfProject.ts +++ b/apps/web/src/lib/skfProject.ts @@ -602,7 +602,11 @@ function activeProjectIndexes(state: SkfStateV1) { function zipAsync(files: AsyncZippable) { return new Promise((resolve, reject) => { - zip(files, { level: 6, mtime: new Date("1980-01-01T00:00:00.000Z") }, (error, data) => { + // fflate encodes the ZIP entry mtime as a DOS date using local-time getters and + // rejects years outside 1980-2099. A UTC-pinned "1980-01-01T00:00:00Z" rolls back + // to 1979 in any timezone west of UTC, so build the epoch from local components to + // keep the year at exactly 1980 everywhere. + zip(files, { level: 6, mtime: new Date(1980, 0, 1) }, (error, data) => { if (error) reject(error); else resolve(data); }); diff --git a/tests/unit/skfProject.test.ts b/tests/unit/skfProject.test.ts index 6355c19..bcf0262 100644 --- a/tests/unit/skfProject.test.ts +++ b/tests/unit/skfProject.test.ts @@ -339,6 +339,23 @@ describe("SketchForge .skf project packages", () => { expect(restored.shapes[1].importedMesh?.positions).toEqual(mesh.positions); }); + it("exports in a far-western timezone without underflowing the ZIP 1980 date floor", async () => { + // ZIP stores entry mtimes as DOS dates, and fflate encodes them with local-time + // getters, rejecting years outside 1980-2099 with "date not in range 1980-2099". + // A UTC-pinned epoch rolls back to 1979 west of UTC, so exercise the fix under the + // most extreme western offset. Node re-reads process.env.TZ per Date operation. + const originalTz = process.env.TZ; + process.env.TZ = "Etc/GMT+12"; + try { + const exported = await exportSkfProject(input([shape("box")])); + const restored = await importSkfProject(exported); + expect(restored.shapes[0].kind).toBe("box"); + } finally { + if (originalTz === undefined) delete process.env.TZ; + else process.env.TZ = originalTz; + } + }); + it("migrates the documented v0 JSON project without changing IDs", async () => { const box = shape("box", "legacy-box"); const legacy = strToU8(JSON.stringify({