👒 fix timezone to utc and perfect example demo

This commit is contained in:
Godruoyi
2021-11-26 13:54:11 +08:00
parent 056fce86b8
commit 937cb414e9
2 changed files with 7 additions and 2 deletions

View File

@@ -2,13 +2,18 @@ package main
import ( import (
"fmt" "fmt"
"time"
"github.com/godruoyi/go-snowflake" "github.com/godruoyi/go-snowflake"
) )
func main() { func main() {
// set starttime and machineID for the first time if you wan't to use the default value
snowflake.SetStartTime(time.Date(2021, 9, 1, 0, 0, 0, 0, time.UTC))
snowflake.SetMachineID(snowflake.PrivateIPToMachineID()) // testing, not to be used in production
id := snowflake.ID() id := snowflake.ID()
fmt.Println(id) fmt.Println(id) // 1537200202186752
sid := snowflake.ParseID(id) sid := snowflake.ParseID(id)
// SID { // SID {

View File

@@ -84,7 +84,7 @@ func SetStartTime(s time.Time) {
panic("The start time cannot be a zero value") panic("The start time cannot be a zero value")
} }
if s.After(time.Now()) { if s.After(time.Now().UTC()) {
panic("The s cannot be greater than the current millisecond") panic("The s cannot be greater than the current millisecond")
} }