summaryrefslogtreecommitdiff
path: root/discord
diff options
context:
space:
mode:
Diffstat (limited to 'discord')
-rw-r--r--discord/snowflake.cpp12
-rw-r--r--discord/snowflake.hpp1
2 files changed, 13 insertions, 0 deletions
diff --git a/discord/snowflake.cpp b/discord/snowflake.cpp
index 5528819..70dee2e 100644
--- a/discord/snowflake.cpp
+++ b/discord/snowflake.cpp
@@ -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;
diff --git a/discord/snowflake.hpp b/discord/snowflake.hpp
index 4cfdc35..2719f98 100644
--- a/discord/snowflake.hpp
+++ b/discord/snowflake.hpp
@@ -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;