forked from pothtonswer/discordmuffin
* Millisecond precision * formatting * Update util.go * remove unnecessary int64 * Add unit test for SnowflakeTimestamp Co-authored-by: NANI <nani@ksoft.si> Co-authored-by: Carson Hoffman <c@rsonhoffman.com>
17 lines
371 B
Go
17 lines
371 B
Go
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(0, timestamp*1000000)
|
|
return
|
|
}
|