Created
November 28, 2012 17:21
-
-
Save jfromaniello/4162658 to your computer and use it in GitHub Desktop.
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
Date.fake(new Date(2019, 0 , 1)) | |
var a = new Date(); // Tue Jan 01 2019 00:00:00 GMT-0300 (ART) | |
Date.unfake(); | |
a.getTime() === new Date(2019, 0, 1).getTime() //true |
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
var oldDate = global.Date; | |
global.Date.fake = function (fix) { | |
var time = fix.getTime(); | |
global.Date = function () { | |
return new oldDate(time); | |
}; | |
global.Date.prototype = Object.create(oldDate.prototype); | |
global.Date.prototype.constructor = global.Date; | |
global.Date.unfake = function () { | |
global.Date = oldDate; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment