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

Fix ISO weekday calculations in negative years #4894

Merged
merged 2 commits into from
May 15, 2024

Conversation

sffc
Copy link
Member

@sffc sffc commented May 13, 2024

Fixes #4893

I thought we had already scrubbed the code of all non-euclidean calculations, but I guess not.

Thanks @anba for noticing this!

@sffc sffc requested a review from Manishearth as a code owner May 13, 2024 17:08
@sffc sffc requested a review from a team as a code owner May 13, 2024 17:09
@sffc sffc requested a review from echeran May 13, 2024 17:57
@sffc
Copy link
Member Author

sffc commented May 13, 2024

Adding @echeran as reviewer since @Manishearth is out of office this week.

Copy link
Member

@robertbastian robertbastian left a comment

Choose a reason for hiding this comment

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

There are five more instances of % in the calendar component: https://github.com/search?q=repo%3Aunicode-org%2Ficu4x+%25+path%3Acomponents%2Fcalendar%2Fsrc%2F&type=code. Please clean them up as well, either by using rem_euclid, or by adding a comment showing that the left argument is non-negative.

@@ -135,7 +135,9 @@ impl Calendar for Iso {

// The days of the week are the same every 400 years
// so we normalize to the nearest multiple of 400
let years_since_400 = date.0.year % 400;
let years_since_400 = date.0.year.rem_euclid(400);
debug_assert!(years_since_400 >= 0); // rem_euclid returns positive numbers
Copy link
Member

Choose a reason for hiding this comment

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

it does, let's not assert std guarantees.

Copy link
Member Author

Choose a reason for hiding this comment

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

I suspected you might leave a comment like this :) ... I still have a slight preference for assertions on code invariants since as casts can be error-prone

@sffc
Copy link
Member Author

sffc commented May 14, 2024

The tracking issue is #2703. Let's merge this improvement. I might go ahead and work on the rest in a follow-up PR.

@sffc
Copy link
Member Author

sffc commented May 15, 2024

The rest is in #4904

@sffc sffc merged commit 6899eda into unicode-org:main May 15, 2024
30 checks passed
@sffc sffc deleted the iso-weekdays branch May 15, 2024 05:02
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.

Incorrect week day for Hebrew calendar when ISO year is negative
2 participants