Skip to content

Instantly share code, notes, and snippets.

@jfromaniello
Created November 28, 2012 17:21
Show Gist options
  • Save jfromaniello/4162658 to your computer and use it in GitHub Desktop.
Save jfromaniello/4162658 to your computer and use it in GitHub Desktop.
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
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