Line data Source code
1 4 : (ns matchscore.utils.uuid
2 : (:import
3 : [com.fasterxml.uuid Generators]))
4 :
5 :
6 12 : (def ^:private uuid7-generator (Generators/timeBasedEpochGenerator))
7 :
8 :
9 4 : (defn generate-uuid7
10 : "Generates a UUID v7 (time-based epoch). Returns a java.util.UUID."
11 : []
12 4 : (.generate uuid7-generator))
13 :
14 :
15 4 : (defn generate-uuid7-str
16 : "Generates a UUID v7 (time-based epoch). Returns a string."
17 : []
18 16 : (str (generate-uuid7)))
19 :
20 :
21 8 : (def ^:private uuid-pattern #"(?i)[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}")
22 :
23 :
24 4 : (defn uuid-string?
25 : "Returns true if s is a valid UUID string (any version)."
26 : [s]
27 48 : (and (string? s) (boolean (re-matches uuid-pattern s))))
|