You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems like TZDate(year, month, day, hour, timeZone) returns the date as it occurs in the given timezone. That's great, and intuitive! However, if the date passed is on the hour that is repeated during a "fall back" transition from Daylight Saving Time to Standard Time, it returns different moments in time based on my local time zone, which shouldn't be related.
From what I can tell, if the provided time zone is the same as my local system timezone or earlier, it uses the lesser offset. For example:
// when local/system time is Los Angeles, where 1am could be offset -7 or -8console.log(newTZDate(2012,10,4,1,'America/Los_Angeles').toString());// offset of -7console.log(newTZDate(2012,10,4,1,'America/Denver').toString());// offset of -7// when local/system time is Denver, where 1am could be offset -6 or -7console.log(newTZDate(2012,10,4,1,'America/Los_Angeles').toString());// offset of -7console.log(newTZDate(2012,10,4,1,'America/Denver').toString());// offset of -6 ❗
import{TZDate}from'@date-fns/tz';// For each "fall back" moment, log the hour before, then the hour that's duplicated, then the hour afterconsole.log('Los Angeles');console.log(newTZDate(2012,10,4,'America/Los_Angeles').toString());console.log(newTZDate(2012,10,4,1,'America/Los_Angeles').toString());console.log(newTZDate(2012,10,4,2,'America/Los_Angeles').toString());console.log('Denver');console.log(newTZDate(2012,10,4,'America/Denver').toString());console.log(newTZDate(2012,10,4,1,'America/Denver').toString());console.log(newTZDate(2012,10,4,2,'America/Denver').toString());console.log('Chicago');console.log(newTZDate(2012,10,4,'America/Chicago').toString());console.log(newTZDate(2012,10,4,1,'America/Chicago').toString());console.log(newTZDate(2012,10,4,2,'America/Chicago').toString());console.log('New York');console.log(newTZDate(2012,10,4,'America/New_York').toString());console.log(newTZDate(2012,10,4,1,'America/New_York').toString());console.log(newTZDate(2012,10,4,2,'America/New_York').toString());/*With system time zone in Los AngelesLos AngelesSun Nov 04 2012 00:00:00 GMT-0700 (Pacific Daylight Time)Sun Nov 04 2012 01:00:00 GMT-0700 (Pacific Daylight Time)Sun Nov 04 2012 02:00:00 GMT-0800 (Pacific Standard Time)DenverSun Nov 04 2012 00:00:00 GMT-0600 (Mountain Daylight Time)Sun Nov 04 2012 01:00:00 GMT-0700 (Mountain Standard Time)Sun Nov 04 2012 02:00:00 GMT-0700 (Mountain Standard Time)ChicagoSun Nov 04 2012 00:00:00 GMT-0500 (Central Daylight Time)Sun Nov 04 2012 01:00:00 GMT-0600 (Central Standard Time)Sun Nov 04 2012 02:00:00 GMT-0600 (Central Standard Time)New YorkSun Nov 04 2012 00:00:00 GMT-0400 (Eastern Daylight Time)Sun Nov 04 2012 01:00:00 GMT-0500 (Eastern Standard Time)Sun Nov 04 2012 02:00:00 GMT-0500 (Eastern Standard Time)*//*With system time zone in DenverLos AngelesSun Nov 04 2012 00:00:00 GMT-0700 (Pacific Daylight Time)Sun Nov 04 2012 01:00:00 GMT-0700 (Pacific Daylight Time)Sun Nov 04 2012 02:00:00 GMT-0800 (Pacific Standard Time)DenverSun Nov 04 2012 00:00:00 GMT-0600 (Mountain Daylight Time)Sun Nov 04 2012 01:00:00 GMT-0600 (Mountain Daylight Time)Sun Nov 04 2012 02:00:00 GMT-0700 (Mountain Standard Time)ChicagoSun Nov 04 2012 00:00:00 GMT-0500 (Central Daylight Time)Sun Nov 04 2012 01:00:00 GMT-0600 (Central Standard Time)Sun Nov 04 2012 02:00:00 GMT-0600 (Central Standard Time)New YorkSun Nov 04 2012 00:00:00 GMT-0400 (Eastern Daylight Time)Sun Nov 04 2012 01:00:00 GMT-0500 (Eastern Standard Time)Sun Nov 04 2012 02:00:00 GMT-0500 (Eastern Standard Time)*//*With system time zone in ChicagoLos AngelesSun Nov 04 2012 00:00:00 GMT-0700 (Pacific Daylight Time)Sun Nov 04 2012 01:00:00 GMT-0700 (Pacific Daylight Time)Sun Nov 04 2012 02:00:00 GMT-0800 (Pacific Standard Time)DenverSun Nov 04 2012 00:00:00 GMT-0600 (Mountain Daylight Time)Sun Nov 04 2012 01:00:00 GMT-0600 (Mountain Daylight Time)Sun Nov 04 2012 02:00:00 GMT-0700 (Mountain Standard Time)ChicagoSun Nov 04 2012 00:00:00 GMT-0500 (Central Daylight Time)Sun Nov 04 2012 01:00:00 GMT-0500 (Central Daylight Time)Sun Nov 04 2012 02:00:00 GMT-0600 (Central Standard Time)New YorkSun Nov 04 2012 00:00:00 GMT-0400 (Eastern Daylight Time)Sun Nov 04 2012 01:00:00 GMT-0500 (Eastern Standard Time)Sun Nov 04 2012 02:00:00 GMT-0500 (Eastern Standard Time)*//*With system time zone in New YorkLos AngelesSun Nov 04 2012 00:00:00 GMT-0700 (Pacific Daylight Time)Sun Nov 04 2012 01:00:00 GMT-0700 (Pacific Daylight Time)Sun Nov 04 2012 02:00:00 GMT-0800 (Pacific Standard Time)DenverSun Nov 04 2012 00:00:00 GMT-0600 (Mountain Daylight Time)Sun Nov 04 2012 01:00:00 GMT-0600 (Mountain Daylight Time)Sun Nov 04 2012 02:00:00 GMT-0700 (Mountain Standard Time)ChicagoSun Nov 04 2012 00:00:00 GMT-0500 (Central Daylight Time)Sun Nov 04 2012 01:00:00 GMT-0500 (Central Daylight Time)Sun Nov 04 2012 02:00:00 GMT-0600 (Central Standard Time)New YorkSun Nov 04 2012 00:00:00 GMT-0400 (Eastern Daylight Time)Sun Nov 04 2012 01:00:00 GMT-0400 (Eastern Daylight Time)Sun Nov 04 2012 02:00:00 GMT-0500 (Eastern Standard Time)*/
The text was updated successfully, but these errors were encountered:
It seems like
TZDate(year, month, day, hour, timeZone)
returns the date as it occurs in the given timezone. That's great, and intuitive! However, if the date passed is on the hour that is repeated during a "fall back" transition from Daylight Saving Time to Standard Time, it returns different moments in time based on my local time zone, which shouldn't be related.From what I can tell, if the provided time zone is the same as my local system timezone or earlier, it uses the lesser offset. For example:
More examples: https://stackblitz.com/edit/js-zbjsdksw?file=index.js
View Code
The text was updated successfully, but these errors were encountered: