-
-
Notifications
You must be signed in to change notification settings - Fork 46.1k
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
Doomsday Algorithm: Fix leap year check #12396
base: master
Are you sure you want to change the base?
Conversation
Replace `!=` in `(year % 400) != 0` (line 49) with `==` Justification: Years that are divisible by 100 (centurian == 100) but not by 400 (year % 400 != 0) are skipped and NOT leap year.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parenthesize a and b
expressions when chaining and
and or
together, to make the precedence clear
Correct the parentheses to make clear the precedence of the conditional check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed the incorrect conditional operator and ensure clarity using parentheses
@@ -46,7 +46,7 @@ def get_week_day(year: int, month: int, day: int) -> str: | |||
) % 7 | |||
day_anchor = ( | |||
DOOMSDAY_NOT_LEAP[month - 1] | |||
if (year % 4 != 0) or (centurian == 0 and (year % 400) == 0) | |||
if (year % 4 != 0) or ((centurian == 0) and (year % 400 != 0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (year % 4 != 0) or ((centurian == 0) and (year % 400 != 0)) | |
if year % 4 != 0 or (centurian == 0 and year % 400 != 0) |
I believe some of the parentheses are unnecessary, order of operations should still be clear due to the higher precedence of %
, ==
, and !=
.
Replace
!=
in(year % 400) != 0
(line 49) with==
Justification: Years that are divisible by 100 (centurian == 100) but not by 400 (year % 400 != 0) are skipped and NOT leap year.
Describe your change:
Checklist: