Skip to content

Commit

Permalink
πŸ‘’ fix timezone to utc and perfect example demo
Browse files Browse the repository at this point in the history
  • Loading branch information
godruoyi committed Nov 26, 2021
1 parent 056fce8 commit 937cb41
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ package main

import (
"fmt"
"time"

"github.com/godruoyi/go-snowflake"
)

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()
fmt.Println(id)
fmt.Println(id) // 1537200202186752

sid := snowflake.ParseID(id)
// SID {
Expand Down
2 changes: 1 addition & 1 deletion snowflake.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func SetStartTime(s time.Time) {
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")
}

Expand Down

0 comments on commit 937cb41

Please sign in to comment.