diff options
author | Ed Tanous <edtanous@google.com> | 2023-01-08 09:05:08 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2023-01-23 22:27:04 +0300 |
commit | c2e320079eeafbc952a6233e31e8a844bbede9ab (patch) | |
tree | d6804f609d73f8662685d43487226e9d688b2c03 /test/redfish-core | |
parent | b1899a0f0b5510f1b1d62f70ce69cebcdc7fa409 (diff) | |
download | bmcweb-c2e320079eeafbc952a6233e31e8a844bbede9ab.tar.xz |
Break out set time function and unit test it
This function is something that's easily unit tested. Do it.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I8d664c77ec4b3a9886128597449c5f9c041b86b3
Diffstat (limited to 'test/redfish-core')
-rw-r--r-- | test/redfish-core/include/utils/time_utils_test.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/redfish-core/include/utils/time_utils_test.cpp b/test/redfish-core/include/utils/time_utils_test.cpp index 035d8ce95b..873a385d1e 100644 --- a/test/redfish-core/include/utils/time_utils_test.cpp +++ b/test/redfish-core/include/utils/time_utils_test.cpp @@ -139,5 +139,37 @@ TEST(Utility, GetDateTimeUintUs) "1970-01-01T00:00:00.000000+00:00"); } +TEST(Utility, DateStringToEpoch) +{ + EXPECT_EQ(dateStringToEpoch("2021-11-30T22:41:35.123456+00:00"), + usSinceEpoch{1638312095123456}); + // no timezone + EXPECT_EQ(dateStringToEpoch("2021-11-30T22:41:35.123456"), + usSinceEpoch{1638312095123456}); + // Milliseconds precision + EXPECT_EQ(dateStringToEpoch("2021-11-30T22:41:35.123"), + usSinceEpoch{1638312095123000}); + // Seconds precision + EXPECT_EQ(dateStringToEpoch("2021-11-30T22:41:35"), + usSinceEpoch{1638312095000000}); + + // Non zero timezone + EXPECT_EQ(dateStringToEpoch("2021-11-30T22:41:35.123456+04:00"), + usSinceEpoch{1638297695123456}); + + // Epoch + EXPECT_EQ(dateStringToEpoch("1970-01-01T00:00:00.000000+00:00"), + usSinceEpoch{0}); + + // Max time + EXPECT_EQ(dateStringToEpoch("9999-12-31T23:59:59.999999+00:00"), + usSinceEpoch{253402300799999999}); + + // Underflow + // Currently gives wrong result + // EXPECT_EQ(dateStringToEpoch("1969-12-30T23:59:59.999999+00:00"), + // std::nullopt); +} + } // namespace } // namespace redfish::time_utils |