Skip to content

Commit

Permalink
doc: update doc strings
Browse files Browse the repository at this point in the history
  • Loading branch information
kohenkatz committed Aug 9, 2024
1 parent be813fc commit ad2043b
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,16 @@ func (g *Gen) NewV5(ns UUID, name string) UUID {
return u
}

// NewV6 returns a k-sortable UUID based on a timestamp and 48 bits of
// NewV6 returns a k-sortable UUID based on the current timestamp and 48 bits of
// pseudorandom data. The timestamp in a V6 UUID is the same as V1, with the bit
// order being adjusted to allow the UUID to be k-sortable.
func (g *Gen) NewV6() (UUID, error) {
return g.NewV6AtTime(g.epochFunc())
}

// NewV6 returns a k-sortable UUID based on the provided timestamp and 48 bits of
// pseudorandom data. The timestamp in a V6 UUID is the same as V1, with the bit
// order being adjusted to allow the UUID to be k-sortable.
func (g *Gen) NewV6AtTime(atTime time.Time) (UUID, error) {
/* https://datatracker.ietf.org/doc/html/rfc9562#name-uuid-version-6
0 1 2 3
Expand Down Expand Up @@ -315,12 +318,14 @@ func (g *Gen) NewV6AtTime(atTime time.Time) (UUID, error) {
return u, nil
}

// NewV7 returns a k-sortable UUID based on the current millisecond precision
// NewV7 returns a k-sortable UUID based on the current millisecond-precision
// UNIX epoch and 74 bits of pseudorandom data.
func (g *Gen) NewV7() (UUID, error) {
return g.NewV7AtTime(g.epochFunc())
}

// NewV7 returns a k-sortable UUID based on the provided millisecond-precision
// UNIX epoch and 74 bits of pseudorandom data.
func (g *Gen) NewV7AtTime(atTime time.Time) (UUID, error) {
var u UUID
/* https://datatracker.ietf.org/doc/html/rfc9562#name-uuid-version-7
Expand Down Expand Up @@ -368,11 +373,12 @@ func (g *Gen) NewV7AtTime(atTime time.Time) (UUID, error) {
return u, nil
}

// getClockSequence returns the epoch and clock sequence for V1,V6 and V7 UUIDs.
//
// When useUnixTSMs is false, it uses the Coordinated Universal Time (UTC) as a count of 100-
// getClockSequence returns the epoch and clock sequence of the provided time,
// used for generating V1,V6 and V7 UUIDs.
//
// nanosecond intervals since 00:00:00.00, 15 October 1582 (the date of Gregorian reform to the Christian calendar).
// When useUnixTSMs is false, it uses the Coordinated Universal Time (UTC) as a count of
// 100-nanosecond intervals since 00:00:00.00, 15 October 1582 (the date of Gregorian
// reform to the Christian calendar).
func (g *Gen) getClockSequence(useUnixTSMs bool, atTime time.Time) (uint64, uint16, error) {
var err error
g.clockSequenceOnce.Do(func() {
Expand Down Expand Up @@ -430,7 +436,7 @@ func (g *Gen) getHardwareAddr() ([]byte, error) {
}

// Returns the difference between UUID epoch (October 15, 1582)
// and current time in 100-nanosecond intervals.
// and the provided time in 100-nanosecond intervals.
func (g *Gen) getEpoch(atTime time.Time) uint64 {
return epochStart + uint64(atTime.UnixNano()/100)
}
Expand Down

0 comments on commit ad2043b

Please sign in to comment.