Add support for multiple units #269
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is my attempt to fix #54 that might help with the new upcoming release of ms. I don't have a lot of experience contributing to open source so it might not be the most optimal solution to the issue, but I'm open to suggestions.
The changes I've implemented redirect
return NaN;
to a new functionmultipleUnits
that loops around the whole string and adds the resulting milliseconds withreduce
, finding all substrings that match the number-unit format and using the parse function on them or returningNaN
if no match is found or if sections of the string do not match the format.For the time being, it allows multiple instances of the same unit and does not check if the time order of the units entered is correct. This is obviously not a professional solution, but I would need some help to figure out how to forbid such format. As expressed before, I take any suggestions regarding fixing this new issue.
Finally, I want to clarify I'm not experienced on testing, so I would like some opinions on the tests I added, their format and some other test that could be convenient.
Thank you for considering checking on my attempt.