diff options
author | rtk0c <[email protected]> | 2022-06-30 21:38:53 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-06-30 21:38:53 -0700 |
commit | 7fe47a9d5b1727a61dc724523b530762f6d6ba19 (patch) | |
tree | e95be6e66db504ed06d00b72c579565bab873277 /app/source/Cplt/Utils/Time.cpp | |
parent | 2cf952088d375ac8b2f45b144462af0953436cff (diff) |
Restructure project
Diffstat (limited to 'app/source/Cplt/Utils/Time.cpp')
-rw-r--r-- | app/source/Cplt/Utils/Time.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/app/source/Cplt/Utils/Time.cpp b/app/source/Cplt/Utils/Time.cpp new file mode 100644 index 0000000..4e79ffa --- /dev/null +++ b/app/source/Cplt/Utils/Time.cpp @@ -0,0 +1,29 @@ +#include "Time.hpp" + +#include <ctime> + +std::string TimeUtils::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 TimeUtils::StringifyTimeStamp(int64_t timeStamp) +{ + if (timeStamp == 0) { + return ""; + } + + namespace chrono = std::chrono; + chrono::milliseconds d{ timeStamp }; + chrono::time_point<chrono::system_clock> tp{ d }; + + return StringifyTimePoint(tp); +} |