-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
feat: add parseISODuration #3151
base: main
Are you sure you want to change the base?
Conversation
80612ab
to
2d3edcd
Compare
Is there any hope to get this in? |
2d3edcd
to
23afceb
Compare
I messaged @kossnocorp. It seems that they are waiting for v3.0.0 release so this can be included there if there won't be any bugs.
|
Perhaps we can re-target for v2 instead of main branch? |
If you need to use the function, please copy-paste the code to your project locally. It's not worth it for us to rebuild the function for v2. |
Alright, fair enough |
First of all, thanks a lot for this workaround.
Is it on purpose? Can this be added to this feature as well? It is supported in libs like luxon or dayjs, so technically it may be possible. Here is an example of luxon and dayjs if you want live example: |
According to the specification all these values are positive and above zero. In my understanding I would assume we should not have a negative day or negative year? |
Agree, but it was the same discussion in other libraries (sorry to link to other libs from here, but this is the one of many discussions: moment/moment#2408 (comment)) Don't mean that if others support it, date-fns must support it - just curious about the roadmap. |
Any chance to get the conflicts resolved so we can still get this into v3? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you a lot for your work and waiting! I finally have time to work on new stuff and will be happy to ship it with the next version
Please rebase and reformat code with the default Prettier config, thanks! |
Rebased it now and all suggestions are applied. However I don't know how to test generated docs to make sure if the example works properly. Let me know if that still has an issue. |
I guess we may need to add more test cases as I have heard a lot about negative values. WDYT? @kossnocorp |
@matinzd don't worry about the docs. Adding more tests never hurt, if you feel there's something to cover please go ahead. |
0ae4193
to
a9d96d0
Compare
What is missing so this can be merged? Anything I can do to help? |
@andrioid |
@matinzd thanks so much for taking care of this. IMO, negative durations shouldn't hold up merging of this feature that has been asked for since 2016 :), especially if negative durations aren't explicitly stated in the standard. Again my opinion, but If it's needed, it can be a followup PR/release. |
@yjukaku Yes, you are right! The test case I found was not related to supporting negative values. Also negative values are not in the standard as far as I checked. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @matinzd, can you let us know what test cases you think can be added before we merge this in? I can help to contribute as well.
* //=> | ||
* const result = { | ||
* years: 3, | ||
* months: 6, | ||
* weeks: 0, | ||
* days: 4, | ||
* hours: 12, | ||
* minutes: 30, | ||
* seconds: 5, | ||
* } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matinzd I think what we need here is for the entire result object to be formatted as a comment. You can refer to src/intervalToDuration/index.ts
for an example.
* //=> | |
* const result = { | |
* years: 3, | |
* months: 6, | |
* weeks: 0, | |
* days: 4, | |
* hours: 12, | |
* minutes: 30, | |
* seconds: 5, | |
* } | |
* //=> { years: 3, months: 6, weeks: 0, days: 4, hours: 12, minutes: 30, seconds: 5 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @matinzd, maybe we could also add more invalid test cases for this, for example:
P
- only PPT
- only P and TP1H
- missing TPT1D
- unneeded TP1W1YT1M
- incorrect date order before TP1WT1M1H
- incorrect time order after T
We could also have:
P0D
- gives zero instead of undefinedPT0S
- gives zero instead of undefinedPT0.0021S
- 0.0021S (instead of 2.1 milliseconds, which could be useful forExtendedDuration
if supported later)
Related: #3150