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 formatting #2162
Comments
As toISOString uses the internal values of _data for the object, the format outputted by toISOString is determined on object creation. Very hacky example for modifying days: Could you use |
@Jervelund I wound up creating this mix-in https://gist.github.com/dennismonsewicz/4f6b4b94f14149b590ca for the project I was working on |
Disclaimer first: I did not buy the ISO specification, so my knowledge about ISO8601 is from wikipedia and other implementations. I assume that moment does not convert correctly according to ISO rules. For example the following two inputs result in the same output:
However, I'd expect different outputs (expectation):
According to the german wikipedia both ISO representations differ at least in case of a clock change (DST), where The problem gets even more obvious when you take examples like this one:
720 hours is the duration of 30 days, which is the duration of a month. Add different libraries creating (moment) and parsing (third party) that ISO date and you come up with quite a lot of fun ;-) For my case I will also have to verify what the parsing library does and if that is correct. But I am quite sure, that it is invalid (from an ISO 8601 standpoint) to simply convert 720 hours to one month. I think the bubbling (see here) should stop at the level of hours. |
One addition: I assume somebody working on moment already knew that this would be sensible:
The difference between 24 hours and 1 day is present in the object, it just vanishes when it comes to ISO formatting... |
Shouldn't duration formatting work similar to date formatting?
There is already a library that does this (jsmreese/moment-duration-format), but it would make sense to include this in the base library. |
So this was a long time ago and I don't really remember the details, but didn't PR #2357 fix this? In that case this issue could probably be closed :) |
Closing, as this is partly fixed and partly a duplicate of #1048 Let me know if anyone has further thoughts. |
When using the
Moment.duration({ days: 67 }).toIsoString()
portion of this library, I am noticing that the ISOString that is formatted isP2M7D
, but, what I need isP67D
which is a more accurate representation of what I need.Is there anyway, using Moment.js, to achieve this? Maybe through some kind of passed in option?
The text was updated successfully, but these errors were encountered: