added SnowflakeTimestamp utility function to obtain the creation date of a discord snowflake ID

This commit is contained in:
necro 2019-04-12 11:19:31 -04:00
parent c5ae321187
commit e3acfe56f0

17
util.go Normal file
View file

@ -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
}