From 538e804fc9beb83e711a210ffbb6badc15f285d5 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Wed, 28 Apr 2021 21:25:55 -0700 Subject: Add table visualization for purchases --- core/src/Utils/Time.cpp | 29 +++++++++++++++++++++++++++++ core/src/Utils/Time.hpp | 7 +++++++ 2 files changed, 36 insertions(+) create mode 100644 core/src/Utils/Time.cpp create mode 100644 core/src/Utils/Time.hpp (limited to 'core/src/Utils') 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 + +std::string StringifyTimePoint(std::chrono::time_point 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 tp{ d }; + + return StringifyTimePoint(tp); +} diff --git a/core/src/Utils/Time.hpp b/core/src/Utils/Time.hpp new file mode 100644 index 0000000..1f5a048 --- /dev/null +++ b/core/src/Utils/Time.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include +#include + +std::string StringifyTimePoint(std::chrono::time_point tp); +std::string StringifyTimeStamp(int64_t timeStamp); -- cgit v1.2.3-70-g09d2