Tests: DateTime: add TimeRoundtrip test (#1613)

Co-authored-by: Anton Kolesnyk <antkmsft@users.noreply.github.com>
This commit is contained in:
Anton Kolesnyk 2021-02-05 16:21:24 -08:00 committed by GitHub
parent 9ed77d8b06
commit 79864623f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,14 +44,19 @@ TEST(DateTime, ParseDateExtended)
}
namespace {
template <DateTime::TimeFractionFormat TF = DateTime::TimeFractionFormat::DropTrailingZeros>
void TestDateTimeRoundtrip(std::string const& str, std::string const& strExpected)
{
auto dt = DateTime::Parse(str, DateTime::DateFormat::Rfc3339);
auto const str2 = dt.GetString(DateTime::DateFormat::Rfc3339);
auto const str2 = dt.GetRfc3339String(TF);
EXPECT_EQ(str2, strExpected);
}
void TestDateTimeRoundtrip(std::string const& str) { TestDateTimeRoundtrip(str, str); }
template <DateTime::TimeFractionFormat TF = DateTime::TimeFractionFormat::DropTrailingZeros>
void TestDateTimeRoundtrip(std::string const& str)
{
TestDateTimeRoundtrip<TF>(str, str);
}
} // namespace
TEST(DateTime, ParseTimeRoundrip1)
@ -634,3 +639,123 @@ TEST(DateTime, ComparisonOperators)
EXPECT_GE(chronoPast, azcorePast);
EXPECT_GE(chronoFuture, azcoreFuture);
}
TEST(DateTime, TimeRoundtrip)
{
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000001Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000002Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000003Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000004Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000005Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000006Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000007Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000008Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000009Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000010Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000020Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000030Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000040Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000050Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000060Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000070Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000080Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000090Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000100Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000200Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000300Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000400Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000500Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000600Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000700Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000800Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0000900Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0001000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0002000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0003000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0004000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0005000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0006000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0007000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0008000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0009000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0010000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0020000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0030000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0040000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0050000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0060000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0070000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0080000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0090000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0100000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0200000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0300000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0400000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0500000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0600000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0700000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0800000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.0900000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.1000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.2000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.3000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.4000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.5000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.6000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.7000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.8000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:00.9000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:01.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:02.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:03.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:04.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:05.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:06.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:07.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:08.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:09.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:10.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:20.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:30.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:40.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:00:50.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:01:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:02:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:03:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:04:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:05:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:06:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:07:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:08:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:09:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:10:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:20:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:30:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:40:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T00:50:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T01:00:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T02:00:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T03:00:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T04:00:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T05:00:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T06:00:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T07:00:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T08:00:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T09:00:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T10:00:00.0000000Z");
TestDateTimeRoundtrip<DateTime::TimeFractionFormat::AllDigits>("2021-02-05T20:00:00.0000000Z");
}