timezone-support icon indicating copy to clipboard operation
timezone-support copied to clipboard

Bug in getUnixTime for DST switch

Open simlu opened this issue 5 years ago • 0 comments

There seems to be a bug in getUnixTime. The unix timestamp is incorrectly generated just after the change to PDT.

I've validated the result and compared the behavior to moment-timezone. See test case below

const moment = require('moment-timezone');
const { findTimeZone, getUnixTime } = require('timezone-support');

const unix1 = getUnixTime(
  { year: 2018, month: 3, day: 11, hours: 5 },
  findTimeZone('America/Vancouver')
) / 1000;
console.log(unix1);
// => 1520773200
// => 1520773200 converts to Sunday March 11, 2018 06:00:00 (am) in time zone America/Vancouver (PDT)
// Reference: https://www.epochconverter.com/timezones?q=1520773200&tz=America%2FVancouver

const unix2 = moment.tz('2018-03-11T05:00:00', 'America/Vancouver').unix();
console.log(unix2);
// => 1520769600
// => 1520769600 converts to Sunday March 11, 2018 05:00:00 (am) in time zone America/Vancouver (PDT)
// Reference: https://www.epochconverter.com/timezones?q=1520769600&tz=America%2FVancouver

Would be great if this could be fixed. It has caused me some headaches as I'm trying to improve performance by migrating from moment-timezone to timezone-support.

Thank you very much for your consideration!

simlu avatar Apr 05 '20 05:04 simlu