diff --git a/sdk/core/azure-core/CHANGELOG.md b/sdk/core/azure-core/CHANGELOG.md index f40443f06..e6e17c49f 100644 --- a/sdk/core/azure-core/CHANGELOG.md +++ b/sdk/core/azure-core/CHANGELOG.md @@ -6,11 +6,13 @@ - Request logs to now include the `accept-range`, `content-range`, `range`, `WWW-Authenticate`, `x-ms-date`, `x-ms-error-code`, `x-ms-range`, and `x-ms-version` headers. - Added default constructor, `Parse()`, and equality comparison operators to `Azure::Core::Uuid`. +- Added an `Azure::Core::ResourceIdentifier` type. ### Breaking Changes ### Bugs Fixed +- Throw `std::invalid_argument` if the value of `TimeFractionFormat` enum passed in to `DateTime::ToString()` is invalid. - `Azure::Core::Uuid::ToString()` is now `const`. ### Other Changes @@ -20,7 +22,6 @@ ### Features Added - Added new constructor for `Azure::Core::Context` that takes a `std::chrono::system_clock::time_point` deadline. This enables creating a new context directly with a deadline. -- Added an `Azure::Core::ResourceIdentifier` type. ### Breaking Changes diff --git a/sdk/core/azure-core/src/datetime.cpp b/sdk/core/azure-core/src/datetime.cpp index e9d0c0d8d..0869ae57c 100644 --- a/sdk/core/azure-core/src/datetime.cpp +++ b/sdk/core/azure-core/src/datetime.cpp @@ -12,6 +12,7 @@ #include #include #include +#include using namespace Azure; @@ -863,6 +864,20 @@ std::string DateTime::ToString(DateFormat format, TimeFractionFormat fractionFor "Unrecognized date format (" + std::to_string(static_cast(format)) + ")."); } + switch (fractionFormat) + { + case TimeFractionFormat::DropTrailingZeros: + case TimeFractionFormat::AllDigits: + case TimeFractionFormat::Truncate: + break; + default: + throw std::invalid_argument( + "Unrecognized time fraction format (" + + std::to_string( + static_cast::type>(fractionFormat)) + + ")."); + } + ThrowIfUnsupportedYear(); int16_t year = 1; diff --git a/sdk/core/azure-core/test/ut/datetime_test.cpp b/sdk/core/azure-core/test/ut/datetime_test.cpp index cb057debb..7f2ea7d85 100644 --- a/sdk/core/azure-core/test/ut/datetime_test.cpp +++ b/sdk/core/azure-core/test/ut/datetime_test.cpp @@ -494,6 +494,13 @@ TEST(DateTime, ToStringInvalid) EXPECT_THROW( dt.ToString(DateTime::DateFormat::Rfc1123, static_cast(3)), std::invalid_argument); + + EXPECT_THROW( + dt.ToString(DateTime::DateFormat::Rfc3339, static_cast(3)), + std::invalid_argument); + EXPECT_THROW( + dt.ToString(DateTime::DateFormat::Rfc3339, static_cast(-3)), + std::invalid_argument); } TEST(DateTime, ParseTimeInvalid2)