format timestamps and place them on the right (#17)

This commit is contained in:
ouwou
2021-01-02 01:02:23 -05:00
parent b863c3740b
commit 5cf2b7c2db
3 changed files with 18 additions and 1 deletions

View File

@@ -1,4 +1,6 @@
#include "snowflake.hpp"
#include <ctime>
#include <iomanip>
Snowflake::Snowflake()
: m_num(Invalid) {}
@@ -23,6 +25,16 @@ bool Snowflake::IsValid() const {
return m_num != Invalid;
}
std::string Snowflake::GetLocalTimestamp() const {
const time_t secs_since_epoch = (m_num / 4194304000) + 1420070400;
const std::tm tm = *localtime(&secs_since_epoch);
std::stringstream ss;
const static std::locale locale("");
ss.imbue(locale);
ss << std::put_time(&tm, "%X %x");
return ss.str();
}
void from_json(const nlohmann::json &j, Snowflake &s) {
if (j.is_string()) {
std::string tmp;

View File

@@ -10,6 +10,7 @@ struct Snowflake {
Snowflake(const Glib::ustring &str);
bool IsValid() const;
std::string GetLocalTimestamp() const;
bool operator==(const Snowflake &s) const noexcept {
return m_num == s.m_num;