Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions uuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bytes"
"errors"
"fmt"
"io"
"os"
"runtime"
"strings"
Expand Down Expand Up @@ -884,6 +885,20 @@ func TestVersion7FromReader(t *testing.T) {
}
}

// NewV7FromReader returns a Version 7 UUID based on the current time and uses
// NewRandomFromReader to get bytes 8-15 of the UUID. Bytes 0-7 from the reader
// are read but are overwritten by the makeV7 function.
// On error, NewV7FromReader returns Nil and an error.
func NewV7FromReader(r io.Reader) (UUID, error) {
uuid, err := NewRandomFromReader(r)
if err != nil {
return uuid, err
}

makeV7(uuid[:])
return uuid, nil
}

func TestVersion7Monotonicity(t *testing.T) {
length := 10000
u1 := Must(NewV7()).String()
Expand Down
17 changes: 0 additions & 17 deletions version7.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

package uuid

import (
"io"
)

// UUID version 7 features a time-ordered value field derived from the widely
// implemented and well known Unix Epoch timestamp source,
// the number of milliseconds seconds since midnight 1 Jan 1970 UTC, leap seconds excluded.
Expand All @@ -29,19 +25,6 @@ func NewV7() (UUID, error) {
return uuid, nil
}

// NewV7FromReader returns a Version 7 UUID based on the current time(Unix Epoch).
// it use NewRandomFromReader fill random bits.
// On error, NewV7FromReader returns Nil and an error.
func NewV7FromReader(r io.Reader) (UUID, error) {
uuid, err := NewRandomFromReader(r)
if err != nil {
return uuid, err
}

makeV7(uuid[:])
return uuid, nil
}

// makeV7 fill 48 bits time (uuid[0] - uuid[5]), set version b0111 (uuid[6])
// uuid[8] already has the right version number (Variant is 10)
// see function NewV7 and NewV7FromReader
Expand Down