-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
node process does not reflect timezone changes #33805
Comments
As far as I understand it, It's not so much a bug in v8 as it's a performance optimization. As @evanlucas notes in the |
OK! lets think a system does not change time-zone regularly, but only one time in it's whole lifecycle. I think it's more appropriate to say, OK, I use nodejs, its a standard and stable runtime/framework/programming language and widely used and should have a stable date module and like every other technology I trust in internals. (like I said, among tens of technologies we use, its only nodejs that is problematic) Also, this way of thinking time-zone shouldn't be changed regularly, let's suppose I as a typical nodejs/express HTTP server developer, have a code like this: (codes are psuedo like code) app.get(`users`, (req,res) => {
res.send(sql.get('users', req.params.page));
}); To catch that only one-time time-zone change in system, instead of setting up those system watches I described in paragraph 1, I, as a typical js/nodejs web developer write: app.get(`users`, (req,res) => {
require('reset-date-cache`)();
res.send(sql.get('users', req.params.page));
}); This is the only way I could make sure I catch the correct time zone for each request. which is of course as noted, so expensive and probably shouldn't be called/used like this. or write a code like: require('reset-date-cache')();
setInterval(require('reset-date-cache'), _24_HOURS); This solution, is not complete , as it may miss lots of requests before clearing cache, and in shorter intervals, it still faces performance issues. (and after all, if it is a good solution, why not built-in into nodejs as @jasnell noted) ? After all I don't think facing problems like we don't think changing time-zones frequently is a good solution for general-purpose programming languages. Thank you @jasnell for devoting time on this. |
Already exists, courtesy of #20026: process.env.TZ = process.env.TZ || '' // resets the date cache |
@bnoordhuis |
You misunderstand what reset-date-cache does. It tells V8 to flush its internal date cache, not that it should query the operating system for the current timezone. The latter is Complicated. If you have some external means of obtaining the current timezone (e.g. |
Oh! Yes, that's advanced stuff for me. 😀 |
Thanks @bnoordhuis :-) totally forgot about that change! |
I don't think there's anything left here to do so I'll take the liberty of closing it out. |
(it reproduces on both platforms)
What steps will reproduce the bug?
node
on terminal 1new Date().getTimezoneOffset()
new Date().getTimezoneOffset()
in node in terminal 1 againnode
again (anothernode
process)new Date().getTimezoneOffset()
reflects the new timezonegetTimezoneOffset()
is just a sampleHow often does it reproduce? Is there a required condition?
always reproduces, no required condition.
What is the expected behavior?
To reflect and update timezone of node process, when timezone of system is changed.
What do you see instead?
I see the old timezone.
Additional information
This bug has been created and reported previously, as I read, some people mentioned that the main bug is with V8, and linked to some bugs there. By the way, all previous reported bugs were closed. I link to everything I found here:
#4022
#20026
#19974
#3449
I created this issue as some time has passed and honestly, I couldn't find out why the previous issues were closed, and V8 discussions were beyond my knowledge.
What is the matter?
We have a system, a rather big one, composed of different programming languages and technologies, all components of our system works fine when timezone changes, except nodejs. There are solutions like https://github.com/evanlucas/reset-date-cache, but suppose node queries sql queries and created date objects from timestamps in sql tables, and timezone needs to be kept updated. the only way to keep it updated is to reset cache on each page request, which as noted in https://github.com/evanlucas/reset-date-cache:
Screenshot of reproduction
The text was updated successfully, but these errors were encountered: