-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dayjs().add(Duration) API #1093
Comments
Day.js does not support adding However, we could support it in the Duration plugin if needed. |
This will be a nice feature added to the It's much like the workaround code mentioned above. Feel free to draft a PR if anyone is interested in it. |
🎉 This issue has been resolved in version 1.9.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Thanks for this feature ! There are issues with the calculation though: dayjs('2020-01-01').add(1, 'month') // 2020-02-01 ✅
dayjs('2020-01-01').add(dayjs.duration(1, 'month')) // 2020-01-31 ❌ Reproduction example: This is because the |
@iamkun I am finding that in 1.11.9 this does not work, with the same invalid date output. It might be a regression! |
Hello, I'm replacing moment.js with
dayjs
in a project.I'm not sure if the APIs are not compatible at this point or I'm making a mistake here:
the output of the above code is:
Looking at the implementation of
add
:dayjs/src/index.js
Lines 220 to 221 in f95ac15
it always expects the first parameter to be a number so that could one reason why this isn't working.
In moment.js we could add a
Duration
to a Moment object: https://momentjs.com/docs/#/manipulating/add/One workaround would be to convert the duration to milliseconds and add it to the
date2
:The text was updated successfully, but these errors were encountered: