Skip to content

Commit

Permalink
feat(snowflake): add MustParse for lazy people
Browse files Browse the repository at this point in the history
  • Loading branch information
DasPoet committed Aug 29, 2021
1 parent d514978 commit 22c49f2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions snowflake.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ func Parse(s string) (Snowflake, error) {
return Snowflake(parsed), err
}

// MustParse is like Parse, but panics if it encounters an error.
func MustParse(s string) Snowflake {
flake, err := Parse(s)
if err != nil {
panic(err)
}
return flake
}

// FromTimestamp generates a Snowflake for the given time.
func FromTimestamp(time time.Time) Snowflake {
return Snowflake(time.UnixMilli()-discordEpoch) << 22
Expand Down

0 comments on commit 22c49f2

Please sign in to comment.