Last active
July 2, 2025 23:49
-
-
Save devheedoo/f2944b2637843b44c2b9a37f09610cb0 to your computer and use it in GitHub Desktop.
Override browser date for testing or something
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(() => { | |
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