diff options
author | rtk0c <[email protected]> | 2021-04-28 21:25:55 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2021-04-28 21:28:34 -0700 |
commit | 538e804fc9beb83e711a210ffbb6badc15f285d5 (patch) | |
tree | 6157a4065cfca3204f3406a4533095214ec3e04b /core/src/Utils/Time.cpp | |
parent | 00fd95526677d670d002ca81069636f0f74b91f7 (diff) |
Add table visualization for purchases
Diffstat (limited to 'core/src/Utils/Time.cpp')
-rw-r--r-- | core/src/Utils/Time.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/core/src/Utils/Time.cpp b/core/src/Utils/Time.cpp new file mode 100644 index 0000000..d8e0bd1 --- /dev/null +++ b/core/src/Utils/Time.cpp @@ -0,0 +1,29 @@ +#include "Time.hpp" + +#include <ctime> + +std::string StringifyTimePoint(std::chrono::time_point<std::chrono::system_clock> tp) { + auto t = std::chrono::system_clock::to_time_t(tp); + + char data[32]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" // C++ doesn't have std::localtime_s + std::strftime(data, sizeof(data), "%Y-%m-%d %H:%M:%S", std::localtime(&t)); +#pragma clang diagnostic pop + + return std::string(data); +} + +std::string StringifyTimeStamp(int64_t timeStamp) { + if (timeStamp == 0) { + return ""; + } + + namespace chrono = std::chrono; + using Clock = chrono::system_clock; + + chrono::milliseconds d{ timeStamp }; + chrono::time_point<chrono::system_clock> tp{ d }; + + return StringifyTimePoint(tp); +} |