You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hmm, there are more strange things going on in this operation.
largestUnit and smallestUnit are both elements from the set {"year", "month", "week", "day"}, cf. asserts in steps 1-2.
Step 6 initialises unitIndex to the unit index before (!) smallestUnit, so when smallestUnit = "day", then unitIndex is initialised to the index of "week".
unitIndex is only ever decremented, which means unit must be an element of the set {"year", "month", "week"}.
But step 8.b.iv handles the case when unit = "day", which doesn't ever occur.
And while there, step 3:
If smallestUnit is "year", return duration.
Could also be simplified to:
If smallestUnit is largestUnit, return duration.
This makes it clearer that no changes will occur when largestUnit is equal to smallestUnit. (When smallestUnit is "year", then largestUnit must be "year", too.)
Step 8:
The loop condition should compare
unitIndex ≥ largestUnitIndex
instead ofunitIndex ≤ largestUnitIndex
.The text was updated successfully, but these errors were encountered: