Skip to content

Commit fca7ac8

Browse files
authored
Merge pull request #1550 from BillyONeal/fix_leap_year_last_day
Fix year calculation for the last day of a leap year.
2 parents eb6801f + 198b034 commit fca7ac8

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Release/src/utilities/asyncrt_utils.cpp

+6
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

+15
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,21 @@ SUITE(datetime)
133133
TestDateTimeRoundtrip(_XPLATSTR("9999-12-31T23:59:59Z"));
134134
}
135135

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

0 commit comments

Comments
 (0)