Change date in my workspace


Hi, I need to change date in my project for some tests. How I can do it?


Rather than changing the system date, which could cause other issues and won’t be reproducible on other machines, I recommend wrapping the call to get the date in another function, then mocking this function in your tests.

For example if in Javascript you’re using Date.getTime() instead you could code it as:

function getTime() {
    return Date.getTime();

then in your test do something like

getTime = function() { return new Date(12345).getTime(); }

and you can easily set the time to whatever you like and it will be reproducible on any computer without having to change actual system settings.