Skip to content

Instantly share code, notes, and snippets.

@Shaddix
Created October 29, 2021 04:01
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 Shaddix/be0d56b4d95bb17ff6140bf34c508196 to your computer and use it in GitHub Desktop.
Save Shaddix/be0d56b4d95bb17ff6140bf34c508196 to your computer and use it in GitHub Desktop.
date modification for playwright
var _Date = null;
var _ticks;
function restoreDate() {
if (!_Date) {
return;
}
Date = _Date;
}
function replaceDate(ticks) {
_ticks = ticks;
if (_Date) {
return;
}
_Date = Date;
// set Date ctor to always return same date, unless called with parameters
Date = function (...args) {
if (args?.length) {
return new _Date(...args);
}
return new _Date(_ticks);
};
Object.getOwnPropertyNames(_Date).forEach(function (name) {
Date[name] = _Date[name];
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment