-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathksuid.go
More file actions
31 lines (25 loc) · 736 Bytes
/
ksuid.go
File metadata and controls
31 lines (25 loc) · 736 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package ksuid
import (
"time"
)
// Epoch gets the Epoch time from when timestamps are generated
// Defaults to 2000-01-01T00:00:00Z but can be overriden if required.
var Epoch = time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC).Unix()
// KSUID is the main representation for a K-Sortable Unique Identifier.
type KSUID struct {
T time.Time
Seq uint32
Partition uint32
}
// Epoch gets the time the KSUID was generated based on the Epoch value.
func (k KSUID) Epoch() uint32 {
return uint32(k.T.Unix() - Epoch)
}
// Binary is an alias for EncodeBinary(k)
func (k KSUID) Binary() []byte {
return EncodeBinary(k)
}
// String returns the KSUID as a string using EncodeHex
func (k KSUID) String() string {
return string(EncodeHex(k))
}