Documentation
¶
Index ¶
- Constants
- Variables
- func IDTime(i ID) time.Time
- type Generator
- type ID
- func (i ID) IsZero() bool
- func (i ID) MarshalBinary() ([]byte, error)
- func (i ID) MarshalJSON() ([]byte, error)
- func (i ID) MarshalText() ([]byte, error)
- func (i ID) RelativeTime() time.Duration
- func (i ID) String() string
- func (i ID) Time(epoch time.Time) time.Time
- func (i *ID) UnmarshalBinary(b []byte) error
- func (i *ID) UnmarshalJSON(b []byte) error
- func (i *ID) UnmarshalText(b []byte) error
- type RelativeTime
Constants ¶
const CentiSecond = time.Millisecond * 10
const MaxWorker = 0b11111_11111
Variables ¶
var Default = Generator{ Epoch: Epoch, Worker: rand.New(rand.NewSource(time.Now().UnixNano())).Uint64() & MaxWorker, // contains filtered or unexported fields }
Default is a default Generator, useful for low volume projects for higher volumes its recommended to create one yourself however
var Epoch = time.Unix(1645568542, 0)
Epoch is the Epoch for the default generator set to 2022-02-22 22:22:22 UTC aka "twosday"
var Epoch2000 = time.Unix(978220800, 0)
Epoch2000 is an alternate default epoch set to 2000-01-01 00:00:00 UTC for a more typical/practical date requires setting up your own Generator object to use it though
Functions ¶
Types ¶
type ID ¶
type ID uint64
ID is a CSID, which is akin to a snowflake as seen in twitter or discord but slightly different. instead of miliseconds the timestamp is stored in centiseconds (10ms) giving the ID format a much longer lifespan (over 1000 years) and to differentiate itself visually is canonically formatted in hexadecimal instead of decimal
func (ID) MarshalBinary ¶
func (ID) MarshalJSON ¶
func (ID) MarshalText ¶
func (ID) RelativeTime ¶
RelativeTime returns a time.RelativeTime of the time in an ID, note with timestamps over 270 years from the epoch it will overflow and not return correctly