提交 9afbb336 编写于 作者: K king

添加从ID解析生成时间的方法

上级 ada92103
......@@ -87,3 +87,7 @@ func NewDefaultIdGenerator(options *IdGeneratorOptions) *DefaultIdGenerator {
func (dig DefaultIdGenerator) NewLong() int64 {
return dig.SnowWorker.NextId()
}
func (dig DefaultIdGenerator) ExtractTime(id int64) time.Time {
return time.UnixMilli(id>>(dig.Options.WorkerIdBitLength+dig.Options.SeqBitLength) + dig.Options.BaseTime)
}
......@@ -2,6 +2,7 @@ package idgen
import (
"sync"
"time"
)
var singletonMutex sync.Mutex
......@@ -27,3 +28,7 @@ func NextId() int64 {
return idGenerator.NewLong()
}
func ExtractTime(id int64) time.Time {
return idGenerator.ExtractTime(id)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册