sinonjs / fake-timers

Fake setTimeout and friends (collectively known as "timers"). Useful in your JavaScript tests. Extracted from Sinon.JS
BSD 3-Clause "New" or "Revised" License
802 stars 105 forks source link

mocking timezone #342

Closed mahmoudmoravej closed 3 years ago

mahmoudmoravej commented 3 years ago

We have used this tool in order to support mocking system clock in our Jest tests. The problem is that our test files run in containers around the world with different timezones. So, it would be great if we could set the timezone in order to make our tests independent from location. This approach makes writing and understanding our test scenarios straightforward.

mAAdhaTTah commented 3 years ago

FWIW, I believe you can control this via env var. In the past, I've added TZ=UTC in my test script to ensure timezone consistency (which was a minor issue when I was writing tests with my Sydney-based colleagues).

mantoni commented 3 years ago

This has been discussed in #48 before and the most reliable solution is to set the TZ environment variable, as @mAAdhaTTah mentioned. It's not possible to adjust the timezone from within JavaScript.