Skip to content

Instantly share code, notes, and snippets.

@DanH42
Created October 7, 2016 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanH42/11c1b6cffadf1c8ae2a9707661f2c476 to your computer and use it in GitHub Desktop.
Save DanH42/11c1b6cffadf1c8ae2a9707661f2c476 to your computer and use it in GitHub Desktop.
Lies to other code on the page about the current date/time
Date = function(Date){
var fakeDate = 1475852400000; // Fri Oct 07 2016 10:00:00 GMT-0500 (CDT)
var bind = Function.bind;
var unbind = bind.bind(bind);
function NewDate(){
if(arguments.length === 0)
arguments = [fakeDate];
return new (unbind(Date, null).apply(null, arguments));
}
NewDate.prototype = Date.prototype;
var names = Object.getOwnPropertyNames(Date);
for(var i = 0; i < names.length; i++){
if(names[i] in NewDate) continue;
var desc = Object.getOwnPropertyDescriptor(Date, names[i]);
Object.defineProperty(NewDate, names[i], desc);
}
return NewDate;
}(Date);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment