Resolves the leap year last day calculation issue. (#1254)
This commit is contained in:
parent
da86ed7ec5
commit
fb869f10af
@ -92,6 +92,11 @@ constexpr ComputeYearResult ComputeYear(int64_t secondsSince1601)
|
||||
int secondsInt = static_cast<int>(secondsLeft - static_cast<int64_t>(year4) * SecondsIn4Years);
|
||||
|
||||
int year1 = secondsInt / SecondsInYear;
|
||||
if (year1 == 4)
|
||||
{
|
||||
// this is the last day in a leap year
|
||||
year1 = 3;
|
||||
}
|
||||
secondsInt -= year1 * SecondsInYear;
|
||||
|
||||
return {year400 * 400 + year100 * 100 + year4 * 4 + year1, secondsInt};
|
||||
|
||||
@ -409,6 +409,13 @@ TEST(DateTime, ParseTimeRfc3339AcceptsLowercaseTZ)
|
||||
TestDateTimeRoundtrip("1970-01-01T00:00:00z", "1970-01-01T00:00:00Z");
|
||||
}
|
||||
|
||||
TEST(DateTime, ParsingTimeRoundtripLeapYearLastDay)
|
||||
{
|
||||
TestDateTimeRoundtrip("2016-12-31T20:59:59Z");
|
||||
TestDateTimeRoundtrip("2020-12-31T20:59:59Z");
|
||||
TestDateTimeRoundtrip("2021-01-01T20:59:59Z");
|
||||
}
|
||||
|
||||
TEST(DateTime, ParseTimeRoundtripAcceptsInvalidNoTrailingTimezone)
|
||||
{
|
||||
// No digits after the dot, or non-digits. This is not a valid input, but we should not choke on
|
||||
|
||||
Loading…
Reference in New Issue
Block a user