mde / timezone-js

DEPRECATED: Timezone-enabled JavaScript Date object. Uses Olson zoneinfo files for timezone data.
824 stars 183 forks source link

Dates are off in timezones that use DST #58

Closed mattjohnsonpint closed 4 years ago

mattjohnsonpint commented 11 years ago

Consider the following:

var ts1 = 1383451200000;
var dt = new timezoneJS.Date(ts1, 'America/New_York');
var ts2 = dt.getTime();

I would expect that ts2 would be equal to ts1 regardless of which timezone I provided, because they are supposed to be UTC. Instead, ts1 is 1383447600000

If I switch to a timezone that doesn't use DST, such as America/Phoenix or Asia/Kolkata then it works as expected.

Or am I wrong in thinking that the input or the output is supposed to be in UTC? The documentation isn't very clear about that. Thanks.

divide0 commented 11 years ago

Your understanding is mostly correct. getTime/setTime works on milliseconds from the Unix epoch. Timezones shouldn't come into it until you try to print out a time in HH:mm:ss format.

There are bugs in timezone-js when you have dates near the DST transitions. It has trouble identifying the correct DST rule to use.

io41 commented 11 years ago

I think this used to work though. See #78