Describe the bug
I am not sure if this has changed, at least I haven't read anything online about it, but it seems like some dayjs operations are not immutable. I experienced this for the add and subtract operations. According to the docs and issue #844 these operations/methods should not be mutable and the expected behavior should be like the expected behavior below.
const now = dayjs()
console.log('today', now.format())
const sevenYearsAgo = now.subtract(7, 'year');
console.log('7 years ago', sevenYearsAgo.format())
console.log('today', now.format())
Outputs
today 2020-11-05T16:30:03+00:00
7 years ago 2013-11-05T16:30:03+00:00
today 2013-11-05T16:30:03+00:00
You can test this out on in the console on the dayjs website
Expected behavior
It should be immutable and not change when calling either add or subtract
today 2020-11-05T16:30:03+00:00
7 years ago 2013-11-05T16:30:03+00:00
today 2020-11-05T16:30:03+00:00
Information
This is really weird.
Yes, Day.js should always be immutable.
I've tested on the node environment, and it works as expected. https://runkit.com/embed/7ytaf9qqtzr6
However, if tested on a browser script, it will fail.
dayjs extend badMutable plugin in website?
https://day.js.org/docs/en/plugin/bad-mutable#docsNav
@UlricGan Correct! I'll remove it soon. THX
This is a website build error, not Day.js itself. Fixed.