3

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?

grg
  • 3,915
  • 3
  • 27
  • 38
user2869195
  • 71
  • 1
  • 6
  • 1
    Timezones change over time. Maybe you're locale was in a different time zone in 1983? According to [Wikipedia](http://en.wikipedia.org/wiki/Time_in_Argentina), "*Argentina determines whether to observe daylight saving time on a year-by-year basis, and individual provinces may opt out of the federal decision. At present, Argentina does not observe daylight saving time.*" and also "*The first official standardization took place on 25 September 1894*" – p.s.w.g Feb 03 '14 at 21:11
  • datetime is hard. http://www.youtube.com/watch?v=-5wpm-gesOY – Daniel A. White Feb 03 '14 at 21:12
  • as the difference is one hour it might have to do with daylight saving settings. check when this was implemented in argentina – Vickel Feb 03 '14 at 21:14

1 Answers1

1

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.

Community
  • 1
  • 1
Matt Johnson-Pint
  • 197,368
  • 66
  • 382
  • 508