Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is it a bug? setting up process.env.TZ depends on order of execution. #3449

Closed
nsisodiya opened this issue Oct 20, 2015 · 16 comments
Closed
Labels
i18n-api Issues and PRs related to the i18n implementation. v8 engine Issues and PRs related to the V8 dependency.

Comments

@nsisodiya
Copy link

screen shot 2015-10-20 at 6 45 01 pm

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.

@nsisodiya
Copy link
Author

Similarly, there are some more issues, when I am trying to find systemTimeZone.
screen shot 2015-10-20 at 6 54 50 pm

@evanlucas
Copy link
Contributor

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).

@mscdex mscdex added the v8 engine Issues and PRs related to the V8 dependency. label Oct 20, 2015
@yamalight
Copy link
Contributor

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

@evanlucas
Copy link
Contributor

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.

@yamalight
Copy link
Contributor

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

@bnoordhuis
Copy link
Member

There are a number of bugs in V8's timezone handling: v8:3445, v8:3547 and v8:3637, maybe more. It's probably related to V8 using localtime(3) for timezone calculations.

@srl295 srl295 added the i18n-api Issues and PRs related to the i18n implementation. label Oct 22, 2015
@srl295
Copy link
Member

srl295 commented Oct 22, 2015

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.

@srl295
Copy link
Member

srl295 commented Oct 22, 2015

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()

@evanlucas
Copy link
Contributor

@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.

@srl295
Copy link
Member

srl295 commented Oct 23, 2015 via email

@srl295
Copy link
Member

srl295 commented Oct 27, 2015

@nsisodiya thoughts?

@nsisodiya
Copy link
Author

@srl295 , you can close issue if you think this is not a bug if !

@srl295
Copy link
Member

srl295 commented Nov 26, 2015

Closing, setting process.env.TZ is not the right way to set the default timezone.

@capaj
Copy link

capaj commented Jan 9, 2017

@srl295 if you don't mind me asking-what is "the right way" to set the default timezone?

@sam-github
Copy link
Contributor

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.

@jcollum-nike
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
i18n-api Issues and PRs related to the i18n implementation. v8 engine Issues and PRs related to the V8 dependency.
Projects
None yet
Development

No branches or pull requests

9 participants