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.05k stars 2.31k forks source link

Incorrect localizer behaviour when extending dayjs with timezone #2735

Open amifsud02 opened 1 month ago

amifsud02 commented 1 month ago

Describe the bug I've integrated this library with React Big Calendar and observed an issue when displaying dates and weekdays with time zones. I'm extending Day.js with the timezone plugin. The calendar functions correctly without the timezone extension, but once the timezone is applied, the dates and weekdays become incorrect—particularly for the month of April.

import dayjs from "dayjs";
import timezone from "dayjs/plugin/timezone";

dayjs.extend(timezone);

const djLocalizer = dayjsLocalizer(dayjs);

console.log(djLocalizer.visibleDays(dayjs().month(3).startOf("month").toDate(), djLocalizer))

Output with dayjs.extends(timezone)

[Sat Mar 30 2024 23:00:00 GMT+0100 (Central European Standard Time), Mon Apr 01 2024 00:00:00 GMT+0200 (Central European Summer Time), Tue Apr 02 2024 00:00:00 GMT+0200 (Central European Summer Time), Wed Apr 03 2024 00:00:00 GMT+0200 (Central European Summer Time), Thu Apr 04 2024 00:00:00 GMT+0200 (Central European Summer Time), Fri Apr 05 2024 00:00:00 GMT+0200 (Central European Summer Time), Sat Apr 06 2024 00:00:00 GMT+0200 (Central European Summer Time), Sun Apr 07 2024 00:00:00 GMT+0200 (Central European Summer Time), Mon Apr 08 2024 00:00:00 GMT+0200 (Central European Summer Time), Tue Apr 09 2024 00:00:00 GMT+0200 (Central European Summer Time), Wed Apr 10 2024 00:00:00 GMT+0200 (Central European Summer Time), Thu Apr 11 2024 00:00:00 GMT+0200 (Central European Summer Time), Fri Apr 12 2024 00:00:00 GMT+0200 (Central European Summer Time), Sat Apr 13 2024 00:00:00 GMT+0200 (Central European Summer Time), Sun Apr 14 2024 00:00:00 GMT+0200 (Central European Summer Time), Mon Apr 15 2024 00:00:00 GMT+0200 (Central European Summer Time), Tue Apr 16 2024 00:00:00 GMT+0200 (Central European Summer Time), Wed Apr 17 2024 00:00:00 GMT+0200 (Central European Summer Time), Thu Apr 18 2024 00:00:00 GMT+0200 (Central European Summer Time), Fri Apr 19 2024 00:00:00 GMT+0200 (Central European Summer Time), Sat Apr 20 2024 00:00:00 GMT+0200 (Central European Summer Time), Sun Apr 21 2024 00:00:00 GMT+0200 (Central European Summer Time), Mon Apr 22 2024 00:00:00 GMT+0200 (Central European Summer Time), Tue Apr 23 2024 00:00:00 GMT+0200 (Central European Summer Time), Wed Apr 24 2024 00:00:00 GMT+0200 (Central European Summer Time), Thu Apr 25 2024 00:00:00 GMT+0200 (Central European Summer Time), Fri Apr 26 2024 00:00:00 GMT+0200 (Central European Summer Time), Sat Apr 27 2024 00:00:00 GMT+0200 (Central European Summer Time), Sun Apr 28 2024 00:00:00 GMT+0200 (Central European Summer Time), Mon Apr 29 2024 00:00:00 GMT+0200 (Central European Summer Time), Tue Apr 30 2024 00:00:00 GMT+0200 (Central European Summer Time), Wed May 01 2024 00:00:00 GMT+0200 (Central European Summer Time), Thu May 02 2024 00:00:00 GMT+0200 (Central European Summer Time), Fri May 03 2024 00:00:00 GMT+0200 (Central European Summer Time), Sat May 04 2024 00:00:00 GMT+0200 (Central European Summer Time)]

Expected behavior

I expect the output to be like this.

Output without dayjs.extends(timezone)

[Sun Mar 31 2024 00:00:00 GMT+0100 (Central European Standard Time), Mon Apr 01 2024 00:00:00 GMT+0200 (Central European Summer Time), Tue Apr 02 2024 00:00:00 GMT+0200 (Central European Summer Time), Wed Apr 03 2024 00:00:00 GMT+0200 (Central European Summer Time), Thu Apr 04 2024 00:00:00 GMT+0200 (Central European Summer Time), Fri Apr 05 2024 00:00:00 GMT+0200 (Central European Summer Time), Sat Apr 06 2024 00:00:00 GMT+0200 (Central European Summer Time), Sun Apr 07 2024 00:00:00 GMT+0200 (Central European Summer Time), Mon Apr 08 2024 00:00:00 GMT+0200 (Central European Summer Time), Tue Apr 09 2024 00:00:00 GMT+0200 (Central European Summer Time), Wed Apr 10 2024 00:00:00 GMT+0200 (Central European Summer Time), Thu Apr 11 2024 00:00:00 GMT+0200 (Central European Summer Time), Fri Apr 12 2024 00:00:00 GMT+0200 (Central European Summer Time), Sat Apr 13 2024 00:00:00 GMT+0200 (Central European Summer Time), Sun Apr 14 2024 00:00:00 GMT+0200 (Central European Summer Time), Mon Apr 15 2024 00:00:00 GMT+0200 (Central European Summer Time), Tue Apr 16 2024 00:00:00 GMT+0200 (Central European Summer Time), Wed Apr 17 2024 00:00:00 GMT+0200 (Central European Summer Time), Thu Apr 18 2024 00:00:00 GMT+0200 (Central European Summer Time), Fri Apr 19 2024 00:00:00 GMT+0200 (Central European Summer Time), Sat Apr 20 2024 00:00:00 GMT+0200 (Central European Summer Time), Sun Apr 21 2024 00:00:00 GMT+0200 (Central European Summer Time), Mon Apr 22 2024 00:00:00 GMT+0200 (Central European Summer Time), Tue Apr 23 2024 00:00:00 GMT+0200 (Central European Summer Time), Wed Apr 24 2024 00:00:00 GMT+0200 (Central European Summer Time), Thu Apr 25 2024 00:00:00 GMT+0200 (Central European Summer Time), Fri Apr 26 2024 00:00:00 GMT+0200 (Central European Summer Time), Sat Apr 27 2024 00:00:00 GMT+0200 (Central European Summer Time), Sun Apr 28 2024 00:00:00 GMT+0200 (Central European Summer Time), Mon Apr 29 2024 00:00:00 GMT+0200 (Central European Summer Time), Tue Apr 30 2024 00:00:00 GMT+0200 (Central European Summer Time), Wed May 01 2024 00:00:00 GMT+0200 (Central European Summer Time), Thu May 02 2024 00:00:00 GMT+0200 (Central European Summer Time), Fri May 03 2024 00:00:00 GMT+0200 (Central European Summer Time), Sat May 04 2024 00:00:00 GMT+0200 (Central European Summer Time)]

Information