isSame does not work correctly with time zones
Describe the bug I passed the same dayjs object to both isSame parameters (with 'day' units) and got false.
Expected behavior The same object should be the same day.
Information
- Day.js Version Whatever is running on the documentation site
- OS: latest Mac
- Browser Chrome 134
- Time zone: Central Daylight Time
i've seen a few issues where people talk about isSame not working correctly, but they all seem to be for cases where you pass in a string. i'm passing in objects here that have explicit time zones.it seems like those time zones are being discarded on one of them, but not both of them
after some more digging, it seems like this may be potentially related to the fact that the clocks change on 3/30 in Germany? but they change at 02:00 on 3/30 and this was looking at 3/29 so im not sure why that would occur.
i think there is a related bug though where if i was to say djs1.endOf('day') using the values above, it would return UTC 21:59:59 which is not correct. it's UTC '22:59:59. endOf('day') is used internally in isSame
Yes, the timezone plugin overrides startOf by
- first removing the timezone info from the date,
- then running the "regular" logic TREATING THE DATE AS LOCAL,
- and finally restoring the timezone info (see: plugin/timezone/index.js#L125-L133)
So:
- we start with
2025-03-29T23:59:00+01:00(CET). - we have the end of the day set to
2025-03-29T23:59:59-07:00(ISO2025-03-30T06:59:59.999Z, so in Europe, it'sCESTat this point) - when the timezone info is added back, we get
2025-03-29T23:59:59+02:00