From ad2043b94516620eef4231cad6c93f730adecce8 Mon Sep 17 00:00:00 2001 From: Moshe Katz Date: Thu, 8 Aug 2024 23:24:20 -0400 Subject: [PATCH] doc: update doc strings --- generator.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/generator.go b/generator.go index 68e7a55..d9a2684 100644 --- a/generator.go +++ b/generator.go @@ -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 @@ -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 @@ -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() { @@ -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) }