From e3acfe56f06abc4eff33d61b2fd8c1696a1b0126 Mon Sep 17 00:00:00 2001 From: necro Date: Fri, 12 Apr 2019 11:19:31 -0400 Subject: [PATCH] added SnowflakeTimestamp utility function to obtain the creation date of a discord snowflake ID --- util.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 util.go diff --git a/util.go b/util.go new file mode 100644 index 0000000..02443ca --- /dev/null +++ b/util.go @@ -0,0 +1,17 @@ +package discordgo + +import ( + "strconv" + "time" +) + +// SnowflakeTimestamp returns the creation time of a Snowflake ID relative to the creation of Discord. +func SnowflakeTimestamp(ID string) (t time.Time, err error) { + i, err := strconv.ParseInt(ID, 10, 64) + if err != nil { + return + } + timestamp := (i >> 22) + 1420070400000 + t = time.Unix(timestamp/1000, 0) + return +}