iamkun / dayjs

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

fixed parsing date with time zone in dayjs.tz() #2774

Open DmytroKondratiuk opened 6 days ago

DmytroKondratiuk commented 6 days ago

When we parse dates in dayjs.tz() with timezone we make time offset twice. So if the date string has timezone information better parse it in dayjs().

Before changes dayjs("2024-09-30 12:43:00 +0300").format('LLLL z') it returns the correct date: Monday, September 30, 2024 12:43 PM GMT+3 dayjs.tz("2024-09-30 12:43:00 +0300").format('LLLL z') it returns the incorrect date: Monday, September 30, 2024 9:43 AM GMT+3 time was offset twice.

After changes dayjs("2024-09-30 12:43:00 +0300").format('LLLL z') it returns the correct date: Monday, September 30, 2024 12:43 PM GMT+3 dayjs.tz("2024-09-30 12:43:00 +0300").format('LLLL z') it returns the correct date: Monday, September 30, 2024 12:43 PM GMT+3 time was offset once.