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

add not woking properly when DST involved #2112

Open maulik1729 opened 2 years ago

maulik1729 commented 2 years ago

dayjs("11-01-2022").tz("America/Boise", true).add(1, "month").toDate() dayjs("12-01-2022").tz("America/Boise", true).toDate() Expected: Should return same Value Current: Getting different values for both

BePo65 commented 2 years ago

oh, you are right. Why didn't anybody notice this error before? Manipulating a Dayjs object created with a timezone will not adjust the offset.

We get the same (wrong) output, when using a setter, e.g. dayjs("11-01-2022").tz("America/Boise", true).month(12).

As 'add' uses 'set' at the end of the method, I suppose this is the culprit. So we probably will need a 'set' method in the plugin 'timezone' that will call the original 'set' and then adjust the offset. Perhaps the existing 'startOf' method can be used as a template.

How about creating a pr for this? Momentarily I don't have the time for a pr.