openpower-pels: time: use gmtime for all operations
The test cases in `bcd_time_test.cpp` could fail if the executing
host were not in UTC. By default the BMC uses UTC but the development
systems are often in a user's local time zone. Switch all time
operations to work off UTC by using gmtime/timegm instead of
localtime/mktime.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I6230fd014f44123fe917a8e2b39e3b903d3a05e8
diff --git a/extensions/openpower-pels/bcd_time.cpp b/extensions/openpower-pels/bcd_time.cpp
index 554a230..cf11951 100644
--- a/extensions/openpower-pels/bcd_time.cpp
+++ b/extensions/openpower-pels/bcd_time.cpp
@@ -43,17 +43,17 @@
using namespace std::chrono;
time_t t = system_clock::to_time_t(time);
- tm* localTime = localtime(&t);
- assert(localTime != nullptr);
+ tm* gmTime = gmtime(&t);
+ assert(gmTime != nullptr);
- int year = 1900 + localTime->tm_year;
+ int year = 1900 + gmTime->tm_year;
bcd.yearMSB = toBCD(year / 100);
bcd.yearLSB = toBCD(year % 100);
- bcd.month = toBCD(localTime->tm_mon + 1);
- bcd.day = toBCD(localTime->tm_mday);
- bcd.hour = toBCD(localTime->tm_hour);
- bcd.minutes = toBCD(localTime->tm_min);
- bcd.seconds = toBCD(localTime->tm_sec);
+ bcd.month = toBCD(gmTime->tm_mon + 1);
+ bcd.day = toBCD(gmTime->tm_mday);
+ bcd.hour = toBCD(gmTime->tm_hour);
+ bcd.minutes = toBCD(gmTime->tm_min);
+ bcd.seconds = toBCD(gmTime->tm_sec);
auto ms = duration_cast<milliseconds>(time.time_since_epoch()).count();
int hundredths = (ms % 1000) / 10;