Reputation: 71
I am having troubles with dates and timezones, wondering why this two different queries give different results. It's rare how it also changes timezones depending on the year I'm trying to send. I am using Firefox 26.0 over Ubuntu
Query:
new Date("1990-04-12T00:00:00-03:00")
Result:
Date {Wed Apr 11 1990 23:00:00 GMT-0400 (WART)}
Query:
new Date("1983-04-12T00:00:00-03:00")
Result:
Date {Tue Apr 12 1983 00:00:00 GMT-0300 (ART)}
Any clue?
Upvotes: 3
Views: 83
Reputation: 241890
JavaScript implementing ECMAScript 5.1 or earlier (that's just about everywhere) is affected by a flawed specification. Basically, even if your computer knows what the correct time zone adjustment was for the date you provided, JavaScript will ignore that and use whatever the current rules are for your own local time zone. It doesn't matter if you pass in 1983, 1990, or any other prior year, it will use the rules that are in effect right now.
This is discussed in detail here, and I blogged about it here.
This is changing for the upcoming ECMAScript 6, but you won't find that implemented in most browsers yet. Even then, it will still use the time zone of the computer where the code is running, it will just use it more accurately.
Edit
Digging further, I am going to guess that you are in Western Argentina, probably using the America/Argentina/San_Luis
zone or one nearby. This zone switches had some changes in 1990, where the standard offset started at UTC-2, then switched to a daylight offset of UTC-4 and then back to a new standard offset of UTC-3. It looks like Western Argentina decided to shift an extra hour over, away from the rest of Argentina. You can see these changes here.
The interesting part to me is that your browser picked up on these historical changes, since it appears Western Argentina has been fixed at UTC-3 since October 2009. It would appear that your browser is correctly identifying the historical change, which goes against what I mentioned above.
It's possible that FireFox on Ubuntu is now following ES6 guidelines. I'll have to check that out. (It didn't last time I checked.)
There are some more details about Western Argentina's time zone history here and here.
Upvotes: 1