Skip to content

Commit

Permalink
[new] Add public format-num-fn
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Oct 29, 2024
1 parent 3e3c91c commit 360c44b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/taoensso/encore.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -6487,7 +6487,10 @@

;;;;

(defn- format-nsecs-num-fn [n-min-fd n-max-fd]
(defn ^:no-doc format-num-fn
"Private, don't use."
{:added "Encore vX.Y.Z (YYYY-MM-DD)"}
[n-min-fd n-max-fd]
#?(:clj
(let [^ThreadLocal nf-proxy
(thread-local-proxy
Expand All @@ -6513,10 +6516,10 @@

(fn [n] (.format nf n)))))

(comment ((format-nsecs-num-fn 2 2) 123123123)) ; "123,123,123.00"
(comment ((format-num-fn 2 2) 123123123)) ; "123,123,123.00"

(let [fmt0 (format-nsecs-num-fn 0 0)
fmt2 (format-nsecs-num-fn 2 2)]
(let [fmt0 (format-num-fn 0 0)
fmt2 (format-num-fn 2 2)]

(defn format-nsecs
"Returns given nanoseconds (long) as formatted human-readable string.
Expand Down
6 changes: 3 additions & 3 deletions test/taoensso/encore_tests.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1605,9 +1605,9 @@
;;;;

(deftest _formatting
[(testing "format-nsecs-num-fn (internal)"
(let [fmt0 (#'enc/format-nsecs-num-fn 0 0)
fmt2 (#'enc/format-nsecs-num-fn 2 2)]
[(testing "format-num-fn"
(let [fmt0 (enc/format-num-fn 0 0)
fmt2 (enc/format-num-fn 2 2)]
[(is (= (fmt0 123123123.5555) "123,123,124"))
(is (= (fmt2 123123123.5555) "123,123,123.56"))
(is (= (fmt2 123123123) "123,123,123.00"))
Expand Down

0 comments on commit 360c44b

Please sign in to comment.