new Date('2015-10-20').getDay()
giving me 2. in first case, and in second case, it is giving me 1.
Only difference is, In first case, I am calling it twice.
Also, Day is a timezone independant concept, I do not know why changing timezone, is giving different result.
Similarly, there are some more issues, when I am trying to find systemTimeZone.
The TZ
environment variable is cached by v8 for a small bit after the first time it is accessed (here when calling new Date()
). It should update after a minute or so (not sure of the exact timeline in which the cache is read again).
Doesn't seem to update after "a minute or so" (4 mins to be precise) for me here too:
➜ node -v
v4.2.1
➜ node
> new Date()
Tue Oct 20 2015 17:04:26 GMT+0200 (CEST)
> new Date('2015-10-20').getDay()
2
> process.env.TZ = 'US/Hawaii'
'US/Hawaii'
> new Date('2015-10-20').getDay()
2
> new Date()
Tue Oct 20 2015 16:08:41 GMT+0100 (HST)
> new Date('2015-10-20').getDay()
2
ok, what if you create a new date object like new Date()
and then try again? That immediately changes it for me. Ultimately, this is how v8 handles changes in the TZ environment variable though. It is not done on the node side.
the date does change immediately, that's true. still totally confused why this happens:
➜ node
> new Date()
Tue Oct 20 2015 17:18:01 GMT+0200 (CEST)
> process.env.TZ = 'US/Hawaii'
'US/Hawaii'
> new Date()
Tue Oct 20 2015 16:18:06 GMT+0100 (HST)
> new Date('2015-10-20')
Tue Oct 20 2015 01:00:00 GMT+0100 (HST)
>
(^C again to quit)
>
➜ node
> process.env.TZ = 'US/Hawaii'
'US/Hawaii'
> new Date('2015-10-20')
Mon Oct 19 2015 14:00:00 GMT-1000 (HST)
is that related to v8 tz handling too? looks like a bug to me
setting process.env.TZ
will also _not_ affect the Intl
(ICU) module's notion of the default tz (unless v8 has hooked it somehow?). Is this variable documented as affecting the default tz?
_edit_ if we want a way to change the default timezone, it should be a v8 feature request.
Also, Day is a timezone independant concept, I do not know why changing timezone, is giving different result
I think because the given code is _parsing_ your string as a date. Try new Date(2015,10,20).getDay()
@srl295 v8 internally calls localtime
on most (if not all) *nix platforms, which can be affected by the TZ
environment variable. I have not seen any official documentation regarding the variable.
So I'm thinking "not a bug, set time zone (in a platform specific way) before
startup"
@nsisodiya thoughts?
@srl295 , you can close issue if you think this is not a bug if !
Closing, setting process.env.TZ
is not the right way to set the default timezone.
@srl295 if you don't mind me asking-what is "the right way" to set the default timezone?
Should be set before the process runs, because it affects much of the initialization code. Probably should be set system wide, or at least for the user.
I'd like to know how to set a timezone in my jest config, if possible https://stackoverflow.com/questions/56261381/how-do-i-set-a-timezone-in-my-jest-config
Most helpful comment
@srl295 if you don't mind me asking-what is "the right way" to set the default timezone?