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
ISO 8601 parsing is not correct and erroneously uses modulo logic #4815
Comments
After looking at your issue with @sarfata, we concluded that the library behaves differently than what you expect but works as intended.
We found that adding
Two functions are available,
Notice that |
You are right, durations work correctly when being added to instants and looking at the returned However, when functions like I'll use properties directly then. |
Please add this finding to our docs at https://github.com/moment/momentjs.com |
Hi, I would like to add the finding to the docs! (If it hasn't been added) |
@emer7 Sure thing, please adjust https://github.com/moment/momentjs.com as you see fit and make a pull request. If you need help, please reach out. |
Description of the Issue and Steps to Reproduce:
Given a duration >=31 days,
moment.duration
will incorrectly parse it with modulo logic, assuming that a month is always 31 days long.For example,
moment.duration("P32D")
is converted into a 1 month 1 day moment.duration. If a duration designator is parsed in that way is added to different time instants, the absolute duration will differ, which is valid under ISO 8601. For example, adding 1 month and 1 day to February 1 is different than adding it to May 1:More generally, all duration elements greater than their assumed modulo are not parsed correctly. For hours,
"PT36H"
should not be parsed as 1 day and 12 hours, but as 36 hours, because daylight saving changes can occur.Steps to reproduce:
Environment:
Chrome 69.0.3497.100 OSX
The text was updated successfully, but these errors were encountered: