Skip to content

Commit

Permalink
Merge pull request #1550 from BillyONeal/fix_leap_year_last_day
Browse files Browse the repository at this point in the history
Fix year calculation for the last day of a leap year.
  • Loading branch information
barcharcraz authored Dec 31, 2020
2 parents eb6801f + 198b034 commit fca7ac8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Release/src/utilities/asyncrt_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

secondsInt -= year1 * SecondsInYear;

// shift back to 1900 base from 1601:
Expand Down
15 changes: 15 additions & 0 deletions Release/tests/functional/utils/datetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,21 @@ SUITE(datetime)
TestDateTimeRoundtrip(_XPLATSTR("9999-12-31T23:59:59Z"));
}

TEST(parsing_time_roundtrip_year_2016)
{
TestDateTimeRoundtrip(_XPLATSTR("2016-12-31T20:59:59Z"));
}

TEST(parsing_time_roundtrip_year_2020)
{
TestDateTimeRoundtrip(_XPLATSTR("2020-12-31T20:59:59Z"));
}

TEST(parsing_time_roundtrip_year_2021)
{
TestDateTimeRoundtrip(_XPLATSTR("2021-01-01T20:59:59Z"));
}

TEST(emitting_time_correct_day) {
const auto test = utility::datetime() + UINT64_C(132004507640000000); // 2019-04-22T23:52:44 is a Monday
const auto actual = test.to_string(utility::datetime::RFC_1123);
Expand Down

0 comments on commit fca7ac8

Please sign in to comment.