Update durations() param to take an array of units #675
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 update also includes a bug to the duration function providing too many terms (i.e. for duration(10000000,1) it provides "2 hours, 46 minutes, 40 seconds"), but that was fixed with adding some additional checks in the for loop's if-else statements.
With this update, you can (instead of providing a terms param with the limiting number of units) provide the param with the array of unit types desired. That unit array can be unordered, and if none of the terms 'fit' in the milliseconds provided, then the smallest-magnitude unit along with 0 is returned (in no other cases will a zero term be displayed).
EX: duration(1, [seconds, days, hours]) returns [“0 seconds”] & duration(60 * 60 * 1000+2000, [hours, ms]) returns ["1 hour", "2000 ms"]