changing process.env.TZ at runtime produces non-deterministic behavior #3286

Closed
sp opened this Issue May 19, 2012 · 3 comments

Projects

None yet

3 participants

@sp
sp commented May 19, 2012

When I run this on MacOS/Linux:

console.log(new Date().toString());

process.env.TZ = 'America/Los_Angeles';

new Date('2012-1-12 02:00 PM');
console.log(new Date().toString());

process.env.TZ = "America/New_York";
new Date('2012-1-12 02:00 PM');
console.log(new Date().toString());

process.env.TZ = 'America/Los_Angeles';

new Date('2012-1-12 02:00 PM');
console.log(new Date().toString());

process.env.TZ = 'America/Chicago';

new Date('2012-1-12 02:00 PM');
console.log(new Date().toString());

process.env.TZ = 'Hongkong';

new Date('2012-1-12 02:00 PM');
console.log(new Date().toString());

process.env.TZ = "America/New_York";
new Date('2012-1-12 02:00 PM');
console.log(new Date().toString());

I usually get:

Sat May 19 2012 09:21:08 GMT-0400 (EDT)
Sat May 19 2012 06:21:08 GMT-0700 (PDT)
Sat May 19 2012 09:21:08 GMT-0400 (EDT)
Sat May 19 2012 09:21:08 GMT-0400 (EDT)
Sat May 19 2012 09:21:08 GMT-0400 (EDT)
Sat May 19 2012 09:21:08 GMT-0400 (EDT)
Sat May 19 2012 09:21:08 GMT-0400 (EDT)

But sometimes I get:

Sat May 19 2012 09:21:11 GMT-0400 (EDT)
Sat May 19 2012 06:21:11 GMT-0700 (PDT)
Sat May 19 2012 06:21:11 GMT-0700 (PDT)
Sat May 19 2012 06:21:11 GMT-0700 (PDT)
Sat May 19 2012 08:21:11 GMT-0500 (CDT)
Sat May 19 2012 08:21:11 GMT-0500 (CDT)
Sat May 19 2012 08:21:11 GMT-0500 (CDT)

And sometimes:

Sat May 19 2012 09:21:10 GMT-0400 (EDT)
Sat May 19 2012 06:21:10 GMT-0700 (PDT)
Sat May 19 2012 06:21:10 GMT-0700 (PDT)
Sat May 19 2012 06:21:10 GMT-0700 (PDT)
Sat May 19 2012 06:21:10 GMT-0700 (PDT)
Sat May 19 2012 21:21:10 GMT+0800 (HKT)
Sat May 19 2012 21:21:10 GMT+0800 (HKT)

or:

Sat May 19 2012 09:20:48 GMT-0400 (EDT)
Sat May 19 2012 06:20:48 GMT-0700 (PDT)
Sat May 19 2012 06:20:48 GMT-0700 (PDT)
Sat May 19 2012 06:20:48 GMT-0700 (PDT)
Sat May 19 2012 06:20:48 GMT-0700 (PDT)
Sat May 19 2012 21:20:48 GMT+0800 (HKT)
Sat May 19 2012 09:20:48 GMT-0400 (EDT)

See discussion at https://groups.google.com/forum/?fromgroups#!topic/nodejs/rt8EFR6gdi8

@bnoordhuis
Node.js Foundation member

The platform date functions in V8 use localtime(3) which has side effects (it updates a bunch of global variables). We shouldn't expect the V8 team to fix it because it doesn't affect them (Chromium is single-threaded, it never sees this issue).

@bnoordhuis bnoordhuis was assigned May 20, 2012
@duro

Any luck on this? Wondering if this has been fixed, because I'm looking for how to set this in my app.

@bnoordhuis
Node.js Foundation member

Any luck on this? Wondering if this has been fixed, because I'm looking for how to set this in my app.

The timezone issues have been fixed in master (including on solaris) but the advice from that mailing list post still stands: set TZ before starting node because it's indeterminate when tzset() is first called. It's a quirk of the POSIX date/time functions.

@bnoordhuis bnoordhuis closed this Dec 14, 2012
@halfdan halfdan referenced this issue in TryGhost/Ghost Oct 24, 2013
Closed

Configurable Timezone #1265

@6a68 6a68 referenced this issue in mozilla/chronicle Jan 2, 2015
Closed

'grunt server' should set process timezone to UTC #61

@lesander lesander referenced this issue in lesander/magister-calendar Sep 10, 2015
Closed

Add option for custom timezone #4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment