Files
site-builder/craft/scripts/fake-date-preload.cjs
T

9 lines
434 B
JavaScript
Raw Normal View History

// Test helper: freeze the wall clock for a child process. FAKE_NOW=<ISO date> (node -r this).
const RealDate = Date;
const fixed = new RealDate(process.env.FAKE_NOW).getTime();
if (!Number.isFinite(fixed)) throw new Error('FAKE_NOW must be a valid ISO date');
class FakeDate extends RealDate {
constructor(...a) { if (a.length === 0) super(fixed); else super(...a); }
static now() { return fixed; }
}
globalThis.Date = FakeDate;