aboutsummaryrefslogtreecommitdiff
path: root/src/com/github/ivarref/yoltq/ext_sys.clj
blob: 692b9348febe7ba4a03b73a6a1460f403bfa04eb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
(ns com.github.ivarref.yoltq.ext-sys
  (:require [datomic.api :as d])
  (:refer-clojure :exclude [random-uuid])
  (:import (java.util UUID)))


(def ^:dynamic *now-ms-atom* nil)
(def ^:dynamic *squuid-atom* nil)
(def ^:dynamic *random-atom* nil)


(defn now-ms []
  (if *now-ms-atom*
    @*now-ms-atom*
    (System/currentTimeMillis)))


(defn squuid []
  (if *squuid-atom*
    (UUID/fromString (str "00000000-0000-0000-0000-" (format "%012d" (swap! *squuid-atom* inc))))
    (d/squuid)))


(defn random-uuid []
  (if *random-atom*
    (UUID/fromString (str "00000000-0000-0000-0000-" (format "%012d" (swap! *random-atom* inc))))
    (UUID/randomUUID)))