diff options
Diffstat (limited to 'discord/snowflake.cpp')
-rw-r--r-- | discord/snowflake.cpp | 12 |
1 files changed, 12 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; |