From e7b44be2e3193db4fb444b53f669ddb9fec7c76b Mon Sep 17 00:00:00 2001 From: Youngjae Lee Date: Sat, 1 Jun 2024 13:42:28 +0900 Subject: [PATCH] fix incorrect timestamp in uuid v6 --- version6.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/version6.go b/version6.go index 339a959..77e0cef 100644 --- a/version6.go +++ b/version6.go @@ -39,12 +39,16 @@ func NewV6() (UUID, error) { +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ - binary.BigEndian.PutUint64(uuid[0:], uint64(now)) + timeHigh := uint32((now >> 28) & 0xffffffff) + timeMid := uint16((now >> 12) & 0xffff) + timeLow := uint16(now & 0x0fff) + timeLow |= 0x6000 // Version 6 + + binary.BigEndian.PutUint32(uuid[0:], timeHigh) + binary.BigEndian.PutUint16(uuid[4:], timeMid) + binary.BigEndian.PutUint16(uuid[6:], timeLow) binary.BigEndian.PutUint16(uuid[8:], seq) - uuid[6] = 0x60 | (uuid[6] & 0x0F) - uuid[8] = 0x80 | (uuid[8] & 0x3F) - nodeMu.Lock() if nodeID == zeroID { setNodeInterface("")