PEL: Convert a BCDTime to epoch milliseconds
Add a new function to convert a BCDTime value from a PEL to the number
of milliseconds since the epoch.
This will be used to put the PEL creation timestamp on D-Bus.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Ic470c9324e959b3e6a7eea29db4162a45dd54fc3
diff --git a/test/openpower-pels/bcd_time_test.cpp b/test/openpower-pels/bcd_time_test.cpp
index 6fe761c..1f444b3 100644
--- a/test/openpower-pels/bcd_time_test.cpp
+++ b/test/openpower-pels/bcd_time_test.cpp
@@ -103,3 +103,20 @@
ASSERT_EQ(getBCDTime(now), getBCDTime(ms));
}
+
+TEST(BCDTimeTest, GetMillisecondsSinceEpochTest)
+{
+ // Convert current time to a BCDTime to use
+ auto now = std::chrono::system_clock::now();
+ uint64_t ms = std::chrono::duration_cast<std::chrono::milliseconds>(
+ now.time_since_epoch())
+ .count();
+ auto bcdTime = getBCDTime(ms);
+
+ // BCDTime only tracks down to hundredths of a second (10ms),
+ // so some precision will be lost converting back to milliseconds.
+ // e.g. 12345 -> 12340
+ ms = ms - (ms % 10);
+
+ EXPECT_EQ(ms, getMillisecondsSinceEpoch(bcdTime));
+}