Move time utils to be in one place
We've accumulated several time utility functions in the http classes.
Time isn't a core HTTP primitive, so http is not where those functions
below.
This commit moves all the time functions from the crow::utility
namespace into the redfish::time_utils namespace, as well as moves the
unit tests.
No code changes where made to the individual functions, with the
exception of changing the namespace on the unit tests.
Tested: Unit tests pass.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I8493375f60aea31899c84ae703e0f71a17dbdb73
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index e806bfa..32afd36 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -38,6 +38,7 @@
#include <error_messages.hpp>
#include <query.hpp>
#include <registries/privilege_registry.hpp>
+#include <utils/time_utils.hpp>
#include <charconv>
#include <filesystem>
@@ -178,7 +179,8 @@
<< strerror(-ret);
return false;
}
- entryTimestamp = crow::utility::getDateTimeUint(timestamp / 1000 / 1000);
+ entryTimestamp =
+ redfish::time_utils::getDateTimeUint(timestamp / 1000 / 1000);
return true;
}
@@ -495,7 +497,8 @@
thisEntry["@odata.id"] = entriesPath + entryID;
thisEntry["Id"] = entryID;
thisEntry["EntryType"] = "Event";
- thisEntry["Created"] = crow::utility::getDateTimeUint(timestamp);
+ thisEntry["Created"] =
+ redfish::time_utils::getDateTimeUint(timestamp);
thisEntry["Name"] = dumpType + " Dump Entry";
if (dumpType == "BMC")
@@ -580,7 +583,7 @@
asyncResp->res.jsonValue["Id"] = entryID;
asyncResp->res.jsonValue["EntryType"] = "Event";
asyncResp->res.jsonValue["Created"] =
- crow::utility::getDateTimeUint(timestamp);
+ redfish::time_utils::getDateTimeUint(timestamp);
asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry";
if (dumpType == "BMC")
@@ -990,7 +993,7 @@
asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
std::pair<std::string, std::string> redfishDateTimeOffset =
- crow::utility::getDateTimeOffsetNow();
+ redfish::time_utils::getDateTimeOffsetNow();
asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
asyncResp->res.jsonValue["DateTimeLocalOffset"] =
@@ -1442,9 +1445,9 @@
thisEntry["Severity"] =
translateSeverityDbusToRedfish(*severity);
thisEntry["Created"] =
- crow::utility::getDateTimeUintMs(*timestamp);
+ redfish::time_utils::getDateTimeUintMs(*timestamp);
thisEntry["Modified"] =
- crow::utility::getDateTimeUintMs(*updateTimestamp);
+ redfish::time_utils::getDateTimeUintMs(*updateTimestamp);
if (filePath != nullptr)
{
thisEntry["AdditionalDataURI"] =
@@ -1565,9 +1568,9 @@
asyncResp->res.jsonValue["Severity"] =
translateSeverityDbusToRedfish(*severity);
asyncResp->res.jsonValue["Created"] =
- crow::utility::getDateTimeUintMs(*timestamp);
+ redfish::time_utils::getDateTimeUintMs(*timestamp);
asyncResp->res.jsonValue["Modified"] =
- crow::utility::getDateTimeUintMs(*updateTimestamp);
+ redfish::time_utils::getDateTimeUintMs(*updateTimestamp);
if (filePath != nullptr)
{
asyncResp->res.jsonValue["AdditionalDataURI"] =
@@ -2106,7 +2109,7 @@
asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
std::pair<std::string, std::string> redfishDateTimeOffset =
- crow::utility::getDateTimeOffsetNow();
+ redfish::time_utils::getDateTimeOffsetNow();
asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
asyncResp->res.jsonValue["DateTimeLocalOffset"] =
redfishDateTimeOffset.second;
@@ -2378,7 +2381,7 @@
asyncResp->res.jsonValue["OverWritePolicy"] = std::move(overWritePolicy);
std::pair<std::string, std::string> redfishDateTimeOffset =
- crow::utility::getDateTimeOffsetNow();
+ redfish::time_utils::getDateTimeOffsetNow();
asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
asyncResp->res.jsonValue["DateTimeLocalOffset"] =
redfishDateTimeOffset.second;
@@ -2578,7 +2581,7 @@
asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
std::pair<std::string, std::string> redfishDateTimeOffset =
- crow::utility::getDateTimeOffsetNow();
+ redfish::time_utils::getDateTimeOffsetNow();
asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
asyncResp->res.jsonValue["DateTimeLocalOffset"] =
redfishDateTimeOffset.second;
@@ -2712,7 +2715,7 @@
asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3;
std::pair<std::string, std::string> redfishDateTimeOffset =
- crow::utility::getDateTimeOffsetNow();
+ redfish::time_utils::getDateTimeOffsetNow();
asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
asyncResp->res.jsonValue["DateTimeLocalOffset"] =
redfishDateTimeOffset.second;
@@ -3195,7 +3198,7 @@
"/redfish/v1/Systems/system/LogServices/PostCodes/Entries";
std::pair<std::string, std::string> redfishDateTimeOffset =
- crow::utility::getDateTimeOffsetNow();
+ redfish::time_utils::getDateTimeOffsetNow();
asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
asyncResp->res.jsonValue["DateTimeLocalOffset"] =
redfishDateTimeOffset.second;
@@ -3302,7 +3305,7 @@
// Get the Created time from the timestamp
std::string entryTimeStr;
entryTimeStr =
- crow::utility::getDateTimeUint(usecSinceEpoch / 1000 / 1000);
+ redfish::time_utils::getDateTimeUint(usecSinceEpoch / 1000 / 1000);
// assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex)
std::ostringstream hexCode;