iamkun / dayjs

⏰ Day.js 2kB immutable date-time library alternative to Moment.js with the same modern API
https://day.js.org
MIT License
46.8k stars 2.29k forks source link

[timezone] wrong `toISOString()` value with zone conversion and DST #1657

Open dzonatan opened 3 years ago

dzonatan commented 3 years ago

Describe the bug

// 'Europe/Vilnius' timezone => GMT+2, DST+1

// zone initialization - ok
dayjs.tz('2022-01-01T00:00:00.000Z', 'Europe/Vilnius').format()
// OUTPUT: '2022-01-01T00:00:00+02:00' ✅
dayjs.tz('2022-01-01T00:00:00.000Z', 'Europe/Vilnius').toISOString()
// OUTPUT: '2021-12-31T22:00:00.000Z' ✅

// zone conversion - fails
dayjs.utc('2021-12-31T22:00:00.000Z').tz('Europe/Vilnius').format()
// OUTPUT: '2022-01-01T00:00:00+02:00' ✅
dayjs.utc('2021-12-31T22:00:00.000Z').tz('Europe/Vilnius').toISOString()
// OUTPUT: '2021-12-31T23:00:00.000Z' ❌
// EXPECTED: '2021-12-31T22:00:00.000Z'

FIY: moment.js handles this properly.

Information

mr-short commented 2 years ago

I am seeing similar 1 hour off issues with timezones (compared to momentjs). Central time is -5/-6 but dayjs is giving 7 hour offset?

dayjs('2021-01-01').tz('America/Chicago').toISOString()
'2021-01-01T07:00:00.000Z'

moment('2021-01-01').tz('America/Chicago').toISOString()
'2021-01-01T06:00:00.000Z'