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
Describe the bug
dayjs incorrectly adds hours when working with timezones with times crossing DST.
Expected behavior
On 2021-03-14 02:00:00 NY shifted clocks 1 hour forward. .hour(..) should take that into consideration. Same for .add(..)
vardayjs=require('dayjs');varutc=require('dayjs/plugin/utc')vartimezone=require('dayjs/plugin/timezone');dayjs.extend(utc)dayjs.extend(timezone)varmoment=require('moment-timezone');console.log(moment.tz("2021-03-14 03:00:00","America/New_York").format());// correct 2021-03-14T03:00:00-04:00console.log(moment.tz("2021-03-14 03:00:00","America/New_York").hour(1).format());// correct 2021-03-14T01:00:00-05:00console.log(dayjs.tz("2021-03-14 03:00:00","America/New_York").format());// correct 2021-03-14T03:00:00-04:00console.log(dayjs.tz("2021-03-14 03:00:00","America/New_York").hour(1).format());// INCORRECT 2021-03-14T01:00:00-04:00, time offset is wrong
Information
Day.js Version: 1.11.7
moment Version: 2.29.4
moment-timezone Version: 0.5.40
OS: macOS 11.6
Browser: node v16.13.0
Time zone: Mon Jan 02 2023 10:42:19 GMT+0100 (Central European Standard Time)
The text was updated successfully, but these errors were encountered:
episage
changed the title
Wrong .add(..) / .hour(..) when using timezones on DST
Incorrect .add(..) / .hour(..) when using timezones on DST
Jan 2, 2023
constNY='America/New_York'describe('issue 2184 - add in timezones on DST',()=>{it('Sun Mar 14 2021 03:00:00 -0400, with "set 1 hour "',()=>{dayjs.extend(timezone)dayjs.extend(utc)constdate='2021-03-14 03:00:00'constgoodAnwser=moment(date).tz(NY).hour(1).format()console.log(dayjs(date).tz(NY).hour(1).format(),// 2021-03-13T01:00:00-05:00goodAnwser// 2021-03-13T01:00:00-05:00)expect(dayjs(date).tz(NY).hour(1).format()).toBe(goodAnwser)// passexpect(dayjs.utc(dayjs(date).utc()).tz(NY).hour(1).format()).toBe(goodAnwser)// pass// expect(dayjs.tz(date, NY).hour(1).format()).toBe(goodAnwser) // is not passing})})
Describe the bug
dayjs incorrectly adds hours when working with timezones with times crossing DST.
Expected behavior
On 2021-03-14 02:00:00 NY shifted clocks 1 hour forward.
.hour(..)
should take that into consideration. Same for.add(..)
Information
Mon Jan 02 2023 10:42:19 GMT+0100 (Central European Standard Time)
The text was updated successfully, but these errors were encountered: