From 6fba7b9ce3bcaf4225e5ab774a15ef7364ed1420 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sun, 5 Apr 2026 01:24:07 +0700 Subject: lib/uuidv7: add method IsEqual This is to simplify checking for equality in if-condition. --- lib/uuidv7/uuidv7.go | 5 +++++ lib/uuidv7/uuidv7_example_test.go | 13 +++++++++++++ pakakeh.go | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/uuidv7/uuidv7.go b/lib/uuidv7/uuidv7.go index e2185c24..5aac01bb 100644 --- a/lib/uuidv7/uuidv7.go +++ b/lib/uuidv7/uuidv7.go @@ -99,6 +99,11 @@ func (id *UUIDv7) Equal(v any) (err error) { return nil } +// IsEqual returns true if id equal with other. +func (id UUIDv7) IsEqual(other UUIDv7) bool { + return id.high == other.high && id.low == other.low +} + // IsZero returns true if all bits is zero. func (id UUIDv7) IsZero() bool { return id.high == 0 && id.low == 0 diff --git a/lib/uuidv7/uuidv7_example_test.go b/lib/uuidv7/uuidv7_example_test.go index df007698..5a71d69e 100644 --- a/lib/uuidv7/uuidv7_example_test.go +++ b/lib/uuidv7/uuidv7_example_test.go @@ -15,6 +15,7 @@ import ( ) func ExampleGenerate() { + // Begin mocking Now and Rand, DO NOT USE in production code. now := time.Date(2026, 3, 9, 14, 20, 0, 123456700, time.UTC) uuidv7.Now = func() time.Time { now = now.Add(time.Second) @@ -65,6 +66,18 @@ func ExampleUUIDv7_Equal() { // uuidv7: not equal, want 019CD2F8-1AE3-774E-BFFF-FFFFFFFFFFFF, got 019CD2F8-2AE3-774E-BFFF-FFFFFFFFFFFF } +func ExampleUUIDv7_IsEqual() { + id := uuidv7.Parse(`019CD2F8-1AE3-774E-BFFF-FFFFFFFFFFFF`) + other := uuidv7.Parse(`019CD2F8-1AE3-774E-BFFF-FFFFFFFFFFF0`) + + fmt.Println(id.IsEqual(id)) + fmt.Println(id.IsEqual(other)) + + // Output: + // true + // false +} + func ExampleUUIDv7_MarshalBinary() { now := time.Date(2026, 3, 9, 14, 20, 0, 123456700, time.UTC) uuidv7.Now = func() time.Time { diff --git a/pakakeh.go b/pakakeh.go index 51c7baa0..84f1788f 100644 --- a/pakakeh.go +++ b/pakakeh.go @@ -6,4 +6,4 @@ package pakakeh // Version of this module. -var Version = `0.62.0` +var Version = `0.62.1` -- cgit v1.3