Skip to content
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

duration({ days: 30 }) and duration(30, "days") return different values when converted to ISO8601 #1683

Open
maorleger opened this issue Nov 3, 2021 · 0 comments

Comments

@maorleger
Copy link

maorleger commented Nov 3, 2021

Describe the bug

input result of calling toISOString
dayjs.duration({ days: 30 }) P30D
dayjs.duration(30, "d") P1M
dayjs.duration(30, "day") P1M
dayjs.duration(30, "days") P1M
dayjs.duration("P30D") P30D

Expected behavior

I expected all of the above calls to return "P30D" as "P30D" has a different meaning than the more ambiguous "P1M" (which has different meaning depending on a given date as an anchor point).

I know P1M can be contentious but shouldn't these be consistent across the board? The docs mention this:

For example, a year can be defined as 366 days, 365 days, 365.25 days, 12 months, or 52 weeks. Trying to convert years to days makes no sense without context. It is much better to use dayjs#diff for calculating days or years between two date times than to use Durations.

Which I agree with - but I also think converting days to years / months also makes no sense without context. What do you think?

Thanks in advance!

Information

  • Day.js Version [e.g. v1.0.0] 1.10.7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant