diff options
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); +} |