summaryrefslogtreecommitdiffstats
path: root/ipmi_fru_info_area.cpp
diff options
context:
space:
mode:
authorPatrick Venture <venture@google.com>2019-07-25 16:34:41 -0700
committerPatrick Venture <venture@google.com>2019-08-08 20:33:00 +0000
commit24c771c85a4955320ef1803f0ded1c2852605bb0 (patch)
tree8b3364187561ed3141bd4b11ae1a77167694ad94 /ipmi_fru_info_area.cpp
parentf4a2085c17a7b4d128d24dc4913b96f2979a0989 (diff)
downloadphosphor-host-ipmid-24c771c85a4955320ef1803f0ded1c2852605bb0.tar.gz
phosphor-host-ipmid-24c771c85a4955320ef1803f0ded1c2852605bb0.zip
fru: support two time string formats
Support parsing two time string formats to enable use of ipmi-fru-parser and entity-manager to provide FRU details on dbus. Tested: Verified the entity-manager dbus output for the FRU MfgDate is now parsed correctly. Signed-off-by: Patrick Venture <venture@google.com> Change-Id: I053ec225b51166269c5a5a800ad8d607fd0cc233
Diffstat (limited to 'ipmi_fru_info_area.cpp')
-rw-r--r--ipmi_fru_info_area.cpp29
1 files changed, 26 insertions, 3 deletions
diff --git a/ipmi_fru_info_area.cpp b/ipmi_fru_info_area.cpp
index 85d2007..b220f02 100644
--- a/ipmi_fru_info_area.cpp
+++ b/ipmi_fru_info_area.cpp
@@ -2,9 +2,11 @@
#include <algorithm>
#include <ctime>
+#include <iomanip>
#include <map>
#include <numeric>
#include <phosphor-logging/elog.hpp>
+#include <sstream>
namespace ipmi
{
@@ -193,6 +195,29 @@ void appendData(const Property& key, const PropertyMap& propMap,
}
}
+std::time_t timeStringToRaw(const std::string& input)
+{
+ // TODO: For non-US region timestamps, pass in region information for the
+ // FRU to avoid the month/day swap.
+ // 2017-02-24 - 13:59:00, Tue Nov 20 23:08:00 2018
+ static const std::vector<std::string> patterns = {"%Y-%m-%d - %H:%M:%S",
+ "%a %b %d %H:%M:%S %Y"};
+
+ std::tm time = {};
+
+ for (const auto& pattern : patterns)
+ {
+ std::istringstream timeStream(input);
+ timeStream >> std::get_time(&time, pattern.c_str());
+ if (!timeStream.fail())
+ {
+ break;
+ }
+ }
+
+ return std::mktime(&time);
+}
+
/**
* @brief Appends Build Date
*
@@ -205,9 +230,7 @@ void appendMfgDate(const PropertyMap& propMap, FruAreaData& data)
auto iter = propMap.find(buildDate);
if ((iter != propMap.end()) && (iter->second.size() > 0))
{
- tm time = {};
- strptime(iter->second.c_str(), "%F - %H:%M:%S", &time);
- time_t raw = mktime(&time);
+ std::time_t raw = timeStringToRaw(iter->second);
// From FRU Spec:
// "Mfg. Date / Time
OpenPOWER on IntegriCloud