Skip to content
This repository

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

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

3 participants

sp Ben Noordhuis Adam Duro
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

Ben Noordhuis

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

Jason Davies jasondavies referenced this issue in mbostock/d3 July 23, 2012
Closed

7 broken tests #718

Adam Duro

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

Ben Noordhuis

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.

Ben Noordhuis bnoordhuis closed this December 14, 2012
Fabian Becker halfdan referenced this issue in TryGhost/Ghost October 24, 2013
Open

Configurable Timezone #1265

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.