Skip to content
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 printing the last day in a 400 year cycle. #1767

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Release/src/utilities/asyncrt_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,12 @@ static compute_year_result compute_year_1601(int64_t secondsSince1601)
secondsSince1601 -= year400 * SecondsIn400Years;

int year100 = static_cast<int>(secondsSince1601 / SecondsIn100Years);
if (year100 == 4)
{
// this is the last day in a 400 year cycle
year100 = 3;
}

secondsSince1601 -= year100 * SecondsIn100Years;

int year4 = static_cast<int>(secondsSince1601 / SecondsIn4Years);
Expand Down
4 changes: 4 additions & 0 deletions Release/tests/functional/utils/datetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ SUITE(datetime)

TEST(parsing_time_roundtrip_year_1604) { TestDateTimeRoundtrip(_XPLATSTR("1604-01-01T00:00:00Z")); }

TEST(parsing_time_roundtrip_year_2000_not_last_day) { TestDateTimeRoundtrip(_XPLATSTR("2000-12-30T00:00:00Z")); }

TEST(parsing_time_roundtrip_year_2000_last_day) { TestDateTimeRoundtrip(_XPLATSTR("2000-12-31T00:00:00Z")); }

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