Created
October 29, 2021 04:01
-
-
Save Shaddix/be0d56b4d95bb17ff6140bf34c508196 to your computer and use it in GitHub Desktop.
date modification for playwright
This file contains 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 _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