-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 year calculation for the last day of a leap year. #1550
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -736,6 +736,12 @@ static compute_year_result compute_year(int64_t secondsSince1900) | |
int secondsInt = static_cast<int>(secondsLeft - year4 * SecondsIn4Years); | ||
|
||
int year1 = secondsInt / SecondsInYear; | ||
if (year1 == 4) | ||
{ | ||
// this is the last day in a leap year | ||
year1 = 3; | ||
} | ||
Comment on lines
+739
to
+743
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given this is being ported here, I want to understand it a bit better:
I don't fully follow what you mean here. Can you please elaborate, with a concrete example. Also, what do you mean by the "current year is the last day of a leap year"? Lastly, what is an example impact of this bug exactly to an end user? cc @antkmsft There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
2020-12-31 results in year1 being 4, despite this code expecting all blocks of 4 years to be handled by SecondsIn4Years.
Should be current "current day is the last day of a leap year"
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It incorrectly prints Thursday 2020-12-31 as Thu 2021-01-01 |
||
|
||
secondsInt -= year1 * SecondsInYear; | ||
|
||
// shift back to 1900 base from 1601: | ||
|
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.
This comment is a little confusing since we are talking about a day, but the variable is year.