Skip to content

Timestamp compatibility issues with V6 #203

@dveeden

Description

@dveeden

Comparing the timestamp of a UUIDv6 generated by google/uuid and other implementations shows differences.
Other implementations don't extract a timestamp in the expected range if the UUID is generated by google/uuid and vice versa.

This is working as expected for UUIDv1 and UUIDv7.

This could be related to #199

package main

import (
	"fmt"

	gofrs_uuid "github.com/gofrs/uuid/v5"
	"github.com/google/uuid"
)

func main() {
	gu6, _ := uuid.NewV6()
	fu6, _ := gofrs_uuid.NewV6()
	inputs := []string{
		"1f0e4913-6530-6eec-a6da-d0c1b525246e", // Python: uuid.uuid6()
		"1f0e4916-3394-6114-b891-1b06f5c9afb5", // util-linux: uuidgen -6
		gu6.String(),                           // google/uuid
		fu6.String(),                           // gofrs/uuid
	}
	for _, input := range inputs {
		fmt.Printf("input: %s\n", input)
		u, err := uuid.Parse(input)
		if err != nil {
			panic(err)
		}
		sec, nsec := u.Time().UnixTime()
		fmt.Printf("google/uuid: %d (sec=%d, nsec=%d)\n", u.Time(), sec, nsec)

		gofrs_u := gofrs_uuid.FromStringOrNil(input)
		if gofrs_u.Version() == 6 {
			t, _ := gofrs_uuid.TimestampFromV6(gofrs_u)
			ts, _ := t.Time()
			fmt.Printf("gofrs/uuid:  %d %s\n\n", t, ts)
		}
	}
}
input: 1f0e4913-6530-6eec-a6da-d0c1b525246e
google/uuid: 2237806412500594412 (sec=211561348450, nsec=59441200)
gofrs/uuid:  139862900781289196 2025-12-29 08:34:38.1289196 +0000 UTC

input: 1f0e4916-3394-6114-b891-1b06f5c9afb5
google/uuid: 2237806424553185556 (sec=211561349655, nsec=318555600)
gofrs/uuid:  139862901534572820 2025-12-29 08:35:53.457282 +0000 UTC

input: 01dece4c-c5db-6800-af2c-e65e72dba03d
google/uuid: 134771868000020480 (sec=1257894000, nsec=2048000)
gofrs/uuid:  8423241750001664 1609-06-24 02:56:15.0001664 +0000 UTC

input: 1dece4cc-5db1-6800-bc98-2c6bb394dfa9
google/uuid: 2156349887999993856 (sec=203415695999, nsec=999385600)
gofrs/uuid:  134771868000000000 2009-11-10 23:00:00 +0000 UTC

https://go.dev/play/p/aRPZQ66Qqw8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions