Merge pull request #641 from Necroforger/develop

added SnowflakeTimestamp utility function
This commit is contained in:
Skippy 2019-04-12 12:44:12 -05:00 committed by GitHub
commit 95a8253ee1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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
}