I’m trying to test an extension designed to work only in my workplace (intranet).
More specifically, I placed breakpoints in points of an alarm-triggered routine, where I read the system time at 2 specific times of the day; one close to midnight and the other around 05:00 P.M.
In order not to have to wait for these two moments of the day, I would like to move the system time close to these two times, but I can’t do it because system administrators have disabled this option.
So I’m here to ask for your help.
It is possible to "override" the Date object so that it returns a fake time shifted (forward or backward) by a constant value decided by me on the spot.
Furthermore, time must flow normally.
Taking a practical example, if I now launch this command in the console:
dt = new Date()
I get
Fri Apr 14 2023 10:50:00 GMT+0200
after overriding it should display
Fri Apr 14 2023 23:50:00 GMT+0200
I want the time moved forward 13 hours.
Of course I should activate this movement with a command like:
shiftDate.move(13)
and to make things right again something like:
shiftDate.reset();
All methodsproperties of the Date object must remain unchanged.
Can you give me a hand please?
Thanks in advance
3
Answers
I found a solution, perhaps trivial but it seems to work.
This article might help.
https://www.browserstack.com/guide/change-time-zone-in-chrome-for-testing
Try
Method 1: Using Developer Tools to Change Chrome Timezone
in particular.Because
Date
is a class, we can extend it to provide additional functionality without tampering with the existing static properties/methods.For instance, you can write a new class like
ShiftedDate
below:And use it as such: