bwmarrin / snowflake

A simple to use Go (golang) package to generate or parse Twitter snowflake IDs
BSD 2-Clause "Simplified" License
2.98k stars 371 forks source link

Alternative to ID.Time()? #35

Closed muscache closed 3 years ago

muscache commented 3 years ago

ID.Time() is a deprecated method. What should I use instead? Thanks

codemedic commented 3 years ago

In PR #33 I have removed ID.Time().

Assuming that #33 will be approved and merged and if this functionality is absolutely necessary, it should be provided via a method on Node since we need the configuration of the node to decode the ID.

t, n, s, err := node.DecomposeID(id)

Where t would give you the time with milliseconds precision, n would be node number and s would be step value. If the node number does not match that of node or if step is out of range then err will be set appropriately.

bwmarrin commented 3 years ago

@muscache

That deprecation notice was added a long time ago when I thought I'd have time to build it's replacement shortly after - but that didn't happen. Currently there is no replacement for ID.Time() and you can continue to use it. Furthermore, once a replacement is accepted I won't remove the old methods for at least several months (if not longer).