Skip to content

Instantly share code, notes, and snippets.

@devheedoo
Last active July 2, 2025 23:49
Show Gist options
  • Save devheedoo/f2944b2637843b44c2b9a37f09610cb0 to your computer and use it in GitHub Desktop.
Save devheedoo/f2944b2637843b44c2b9a37f09610cb0 to your computer and use it in GitHub Desktop.
Override browser date for testing or something
(() => {
const dayDiff = 2
const offsetMs = dayDiff * 24 * 60 * 60 * 1000; // 이틀 = 2일 * 24시간 * 60분 * 60초 * 1000ms
const futureTime = Date.now() + offsetMs;
const OriginalDate = Date;
class MockDate extends OriginalDate {
constructor(...args) {
if (args.length === 0) {
return new OriginalDate(futureTime);
}
return new OriginalDate(...args);
}
static now() {
return futureTime;
}
static parse = OriginalDate.parse;
static UTC = OriginalDate.UTC;
static get [Symbol.species]() {
return OriginalDate;
}
}
window.Date = MockDate;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment