fru-device: Remove the use of mktime
mktime get the time in localtime and will mess up the time if the
timezone != UTC. The FRU data should be the raw data in UTC and the
reader will convert to localtime at their end.
This issue is detected when we change the timezone to PST/PDT with
https://gerrit.openbmc.org/c/openbmc/openbmc/+/58293
and the FRU EEPROM time does not match the expected Mfg Date anymore.
Used the timestamp of 1/1/1996 UTC directly.
Data Reader:
https://gerrit.openbmc.org/c/openbmc/phosphor-host-ipmid/+/58466
Tested:
Fru EEPROM Mfg Time now is in the same (after timezone conversion)
between the raw data and FRU output.
Change-Id: I48f9233ee96b676428ba9e9f9f6b34d3da74e612
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/src/fru_utils.cpp b/src/fru_utils.cpp
index 0bb92b9..efae675 100644
--- a/src/fru_utils.cpp
+++ b/src/fru_utils.cpp
@@ -459,14 +459,14 @@
*(fruBytesIter + 1) << 8 |
*(fruBytesIter + 2) << 16;
std::tm fruTime = intelEpoch();
- std::time_t timeValue = std::mktime(&fruTime);
+ std::time_t timeValue = timegm(&fruTime);
timeValue += static_cast<long>(minutes) * 60;
fruTime = *std::gmtime(&timeValue);
// Tue Nov 20 23:08:00 2018
std::array<char, 32> timeString = {};
auto bytes = std::strftime(timeString.data(), timeString.size(),
- "%Y-%m-%d - %H:%M:%S", &fruTime);
+ "%Y-%m-%d - %H:%M:%S UTC", &fruTime);
if (bytes == 0)
{
std::cerr << "invalid time string encountered\n";