You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dates created after a change in the surrounding TZ environment variable have incorrect results from getTimezoneOffset(). This could be related to the cache used in tzOffset - I've noticed that the offsetFormatCache used internally gets an entry for when the timezone is undefined
I've created a Code Sandbox to demonstrate this issue, and if that doesn't work I've pasted the code below:
import{TZDateMini}from"@date-fns/tz";process.env.TZ="America/Los_Angeles";letimplicitLosAngelesDate=newTZDateMini(2024,0);// Returns 480, which is correctconsole.log(implicitLosAngelesDate.getTimezoneOffset());constexplicitMelbourneDate=newTZDateMini(2024,0,"Australia/Melbourne");// Returns -660, which is correctconsole.log(explicitMelbourneDate.getTimezoneOffset());process.env.TZ="Australia/Melbourne";constimplicitMelbourneDate=newTZDateMini(2024,0);// Should be -600, but returns 480 insteadconsole.log(implicitMelbourneDate.getTimezoneOffset());
The use case I had when I ran into this bug was unit testing a complex application in a variety of browser timezones, simulated in a node script. Running consecutive tests with changes to the TZ environment variable wouldn't pick up on the changes to the environment variable, which would cause non-deterministic behaviour between running tests all at once vs running the tests one-by-one.
The text was updated successfully, but these errors were encountered:
ben-cook
changed the title
tzOffset cache ignores changes to environment
timezone offsets incorrect when environment timezone changes
Nov 22, 2024
Dates created after a change in the surrounding
TZ
environment variable have incorrect results fromgetTimezoneOffset()
. This could be related to the cache used intzOffset
- I've noticed that theoffsetFormatCache
used internally gets an entry for when thetimezone
isundefined
I've created a Code Sandbox to demonstrate this issue, and if that doesn't work I've pasted the code below:
The use case I had when I ran into this bug was unit testing a complex application in a variety of browser timezones, simulated in a node script. Running consecutive tests with changes to the
TZ
environment variable wouldn't pick up on the changes to the environment variable, which would cause non-deterministic behaviour between running tests all at once vs running the tests one-by-one.The text was updated successfully, but these errors were encountered: