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

Add parseISODuration function #3768

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

ckcherry23
Copy link
Contributor

This is a continuation of PR #3151 by @matinzd.

Mainly I have:

  • Fixed the docs formatting
  • Added more edge cases in the tests
  • Made it invalid to use durations with just P or nothing after T as per the Wikipedia page
  • However, we still accept decimal values for any unit (eg. P0.5YT1M), even though the standard accepts decimal values only for the last unit specified (eg. P0.5Y)

@ckcherry23 ckcherry23 changed the title Add parseISODuration function Add parseISODuration function Apr 15, 2024
src/parseISODuration/index.ts Outdated Show resolved Hide resolved
hours = 0,
minutes = 0,
seconds = 0,
] = match;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the idea of assigning undefined values to 0. I know that formatISODuration assigns zero values, but these two functions together lose information. I recently played with Temporal's duration, and there you can format(parse('P1Y2M')) === 'P1Y2M', which I think is a very good approach. While we can't change formatISODuration in v3, we can move in that direction.

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree! I've updated the implementation to preserve undefined values instead of assigning them to 0.

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

Successfully merging this pull request may close these issues.

None yet

3 participants