Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 198b034

Browse files
Fix year calculation for the last day of a leap year.
1 parent eb6801f commit 198b034

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

‎Release/src/utilities/asyncrt_utils.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,12 @@ static compute_year_result compute_year(int64_t secondsSince1900)
736736
int secondsInt = static_cast<int>(secondsLeft - year4 * SecondsIn4Years);
737737

738738
int year1 = secondsInt / SecondsInYear;
739+
if (year1 == 4)
740+
{
741+
// this is the last day in a leap year
742+
year1 = 3;
743+
}
744+
739745
secondsInt -= year1 * SecondsInYear;
740746

741747
// shift back to 1900 base from 1601:

‎Release/tests/functional/utils/datetime.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,21 @@ SUITE(datetime)
133133
TestDateTimeRoundtrip(_XPLATSTR("9999年12月31日T23:59:59Z"));
134134
}
135135

136+
TEST(parsing_time_roundtrip_year_2016)
137+
{
138+
TestDateTimeRoundtrip(_XPLATSTR("2016年12月31日T20:59:59Z"));
139+
}
140+
141+
TEST(parsing_time_roundtrip_year_2020)
142+
{
143+
TestDateTimeRoundtrip(_XPLATSTR("2020年12月31日T20:59:59Z"));
144+
}
145+
146+
TEST(parsing_time_roundtrip_year_2021)
147+
{
148+
TestDateTimeRoundtrip(_XPLATSTR("2021年01月01日T20:59:59Z"));
149+
}
150+
136151
TEST(emitting_time_correct_day) {
137152
const auto test = utility::datetime() + UINT64_C(132004507640000000); // 2019年04月22日T23:52:44 is a Monday
138153
const auto actual = test.to_string(utility::datetime::RFC_1123);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /