Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Daylight Saving Time in Javascript for 1974?

Tags:

javascript

dst

"During the "energy crisis" years, Congress enacted earlier starting dates for daylight time. In 1974, daylight time began on 6 January and in 1975 it began on 23 February. After those two years the starting date reverted back to the last Sunday in April. "
(via http://aa.usno.navy.mil/faq/docs/daylight_time.php )

There appears to be a bug in the Javascript date object for these dates. If you convert 127627200000 milliseconds to a date, it should be Thu Jan 17 00:00:00 EDT 1974. This is correct on http://www.fileformat.info/tip/java/date2millis.htm, but incorrect on http://www.esqsoft.com/javascript_examples/date-to-epoch.htm, which says it converts to Wed Jan 16 1974 23:00:00 GMT-0500 (Eastern Standard Time). If you create a new Date(127627200000) object in javascript, it gives the latter date conversion. This happens in all major browsers.

I can't imagine this is first time this has been a problem for anyone, but I can't find any other cases of this problem with a few searches online. Does anyone know if there is an existing fix for this or an easier fix than manually checking the dates Javascript has the conversion wrong? Are there other dates this is a problem?

like image 333
jeffl8n Avatar asked Jan 19 '10 19:01

jeffl8n


People also ask

Does Javascript Date handle Daylight Savings?

The answer is Yes. If we are considering New York, USA, then during Daylight Saving, the offset is -4, whereas it would otherwise be -5. There's a solution for this as well: an additional function while obtaining destination city's UTC offset.

When did Daylight Savings Time start in 1974?

Then, beginning on January 6, 1974, implementing the Daylight Saving Time Energy Act, clocks were set ahead. On October 5, 1974, Congress amended the Act, and Standard Time returned on October 27, 1974. Daylight Saving Time resumed on February 23, 1975 and ended on October 26, 1975.

What time is daylight savings JS?

Daylight Saving Time - When do we change our clocks? Most of the United States begins Daylight Saving Time at 2:00 a.m. on the second Sunday in March and reverts to standard time on the first Sunday in November.

Why did Daylight Savings Time start in 1970?

In the early 1970s, America was facing an energy crisis so the government tried an experiment. Congress passed a law to make Daylight Savings Time permanent year round, but just for two years. The thinking was more sunlight in the evening would reduce the nation's energy consumption.


1 Answers

As ever, it's best to check the spec :)

In this case, I was pretty shocked to see this in section 15.9.1.9 of ECMA-262:

The implementation of ECMAScript should not try to determine whether the exact time was subject to daylight saving time, but just whether daylight saving time would have been in effect if the current daylight saving time algorithm had been used at the time. This avoids complications such as taking into account the years that the locale observed daylight saving time year round.

In other words, a conformant ECMAScript implementation is not allowed to be historically accurate.

Now whether all implementations follow this or not, I'm not sure... but it does suggest you'd need some kind of separate library if you wanted to get historically accurate time zones... where "historically accurate" doesn't have to be nearly as far back as 1974, of course: the US changed its DST schedule in 2007, and other countries have done so more recently than that (and with less warning).


1 The first occurrence of 15.9.1.9. For some reason it occurs twice - once for "Daylight Saving Time Adjustment" and once for "Local Time". Wow.

like image 97
Jon Skeet Avatar answered Oct 07 '22 10:10

Jon Skeet