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

BubbleRelativeDuration: Wrong operator for loop condition #2890

Open
anba opened this issue Jun 7, 2024 · 1 comment
Open

BubbleRelativeDuration: Wrong operator for loop condition #2890

anba opened this issue Jun 7, 2024 · 1 comment

Comments

@anba
Copy link
Contributor

anba commented Jun 7, 2024

Step 8:

Repeat, while unitIndex ≤ largestUnitIndex and done is false,

The loop condition should compare unitIndex ≥ largestUnitIndex instead of unitIndex ≤ largestUnitIndex.

@anba
Copy link
Contributor Author

anba commented Jun 7, 2024

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:

  1. If smallestUnit is "year", return duration.

Could also be simplified to:

  1. 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.)

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

No branches or pull requests

1 participant