aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-04-05 01:24:07 +0700
committerShulhan <ms@kilabit.info>2026-04-05 02:51:14 +0700
commit6fba7b9ce3bcaf4225e5ab774a15ef7364ed1420 (patch)
treeb71bc2f1e1fc796da32f3276934f8a069ac2b081
parent46541a14a6fec773245aaa79e6c0a8dadcf44d64 (diff)
downloadpakakeh.go-6fba7b9ce3bcaf4225e5ab774a15ef7364ed1420.tar.xz
lib/uuidv7: add method IsEqual
This is to simplify checking for equality in if-condition.
-rw-r--r--lib/uuidv7/uuidv7.go5
-rw-r--r--lib/uuidv7/uuidv7_example_test.go13
-rw-r--r--pakakeh.go2
3 files changed, 19 insertions, 1 deletions
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`