Fix DateTime::Parse validation for dates past year 9999 due to adjustments (#3177)
This commit is contained in:
parent
d4ffa7dbc1
commit
12a2ca31bc
@ -10,6 +10,8 @@
|
||||
|
||||
### Bugs Fixed
|
||||
|
||||
- Fixed `Azure::DateTime::Parse()` validation if the result is going to exceed `9999-12-31T23:59:59.9999999` due to time zone, leap second, or fractional digits rounding up adjustments.
|
||||
|
||||
### Other Changes
|
||||
|
||||
## 1.3.1 (2021-11-05)
|
||||
|
||||
@ -236,7 +236,7 @@ void ValidateDate(
|
||||
+ (hour * OneHourIn100ns) + (minute * OneMinuteIn100ns) + (second * OneSecondIn100ns)
|
||||
+ fracSec + (roundFracSecUp ? 1 : 0);
|
||||
|
||||
constexpr auto FracSecTo9999_12_31_23_59_59_9999999 = (31 * OneDayIn100ns)
|
||||
constexpr auto FracSecTo9999_12_31_23_59_59_9999999 = (30 * OneDayIn100ns)
|
||||
+ (23 * OneHourIn100ns) + (59 * OneMinuteIn100ns) + (59 * OneSecondIn100ns) + 9999999;
|
||||
|
||||
if (fracSecSince9999_12_01 - fracSecTimeAdjustment > FracSecTo9999_12_31_23_59_59_9999999)
|
||||
|
||||
@ -802,3 +802,20 @@ TEST(DateTime, TimeRoundtrip)
|
||||
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T10:00:00.0000000Z");
|
||||
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T20:00:00.0000000Z");
|
||||
}
|
||||
|
||||
TEST(DateTime, ParseRoundUpInvalidDate)
|
||||
{
|
||||
EXPECT_THROW(
|
||||
static_cast<void>(
|
||||
DateTime::Parse("9999-12-31T23:59:00-00:01", DateTime::DateFormat::Rfc3339)),
|
||||
std::invalid_argument);
|
||||
|
||||
EXPECT_THROW(
|
||||
static_cast<void>(
|
||||
DateTime::Parse("9999-12-31T23:59:59.99999995", DateTime::DateFormat::Rfc3339)),
|
||||
std::invalid_argument);
|
||||
|
||||
EXPECT_THROW(
|
||||
static_cast<void>(DateTime::Parse("9999-12-31T23:59:60", DateTime::DateFormat::Rfc3339)),
|
||||
std::invalid_argument);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user