|
9 | 9 | #?@(:cljs |
10 | 10 | [[cljs-time.coerce :refer [from-date]] |
11 | 11 | [cljs-time.format :refer [formatter unparse]] |
12 | | - [goog.string :refer [format]] |
13 | | - [goog.object :as gobj]])) |
14 | | - #?(:clj (:import (java.text SimpleDateFormat) |
15 | | - (java.util TimeZone) |
16 | | - (java.sql Timestamp)))) |
| 12 | + [goog.string :refer [format]]])) |
| 13 | + #?(:clj |
| 14 | + (:import (java.text SimpleDateFormat) |
| 15 | + (java.util TimeZone) |
| 16 | + (java.sql Timestamp)))) |
17 | 17 |
|
18 | 18 | (defn get-type-name |
19 | 19 | "Get the type of the given object as a string. For Clojure, gets the name of |
20 | 20 | the class of the object. For ClojureScript, gets either the `name` attribute |
21 | 21 | or the protocol name if the `name` attribute doesn't exist." |
22 | 22 | [x] |
23 | | - #?(:clj (.getName (class x)) |
24 | | - :cljs (let [t (type x) |
25 | | - n (.-name t)] |
26 | | - (if (empty? n) |
27 | | - (pr-str t) |
28 | | - n)))) |
| 23 | + #?(:clj |
| 24 | + (.getName (class x)) |
| 25 | + :cljs |
| 26 | + (let [t (type x) |
| 27 | + n (.-name t)] |
| 28 | + (if (empty? n) |
| 29 | + (pr-str t) |
| 30 | + n)))) |
29 | 31 |
|
30 | 32 | (defn print-deletion [printer expr] |
31 | 33 | (let [no-color (assoc printer :print-color false)] |
|
77 | 79 | (if (coll? v) (:map-coll-separator printer) " ") |
78 | 80 | (puget/format-doc printer v)])))) |
79 | 81 |
|
80 | | - |
81 | | -#?(:clj (def ^:private ^ThreadLocal thread-local-utc-date-format |
82 | | - (proxy [ThreadLocal] [] |
83 | | - (initialValue [] |
84 | | - (doto (SimpleDateFormat. "yyyy-MM-dd'T'HH:mm:ss.SSS-00:00") |
85 | | - (.setTimeZone (TimeZone/getTimeZone "GMT")))))) |
86 | | - :cljs (def thread-local-utc-date-format |
87 | | - (doto (cljs-time.format/formatter "yyyy-MM-dd'T'HH:mm:ss.SSS-00:00")))) |
| 82 | +#?(:clj |
| 83 | + (def ^:private ^ThreadLocal thread-local-utc-date-format |
| 84 | + (proxy [ThreadLocal] [] |
| 85 | + (initialValue [] |
| 86 | + (doto (SimpleDateFormat. "yyyy-MM-dd'T'HH:mm:ss.SSS-00:00") |
| 87 | + (.setTimeZone (TimeZone/getTimeZone "GMT")))))) |
| 88 | + :cljs |
| 89 | + (def thread-local-utc-date-format |
| 90 | + (doto (cljs-time.format/formatter "yyyy-MM-dd'T'HH:mm:ss.SSS-00:00")))) |
88 | 91 |
|
89 | 92 | (def ^:private print-date |
90 | 93 | (puget/tagged-handler |
91 | 94 | 'inst |
92 | | - #?(:clj #(.format ^SimpleDateFormat (.get thread-local-utc-date-format) %) |
93 | | - :cljs (fn [input-date] |
94 | | - (let [dt (from-date input-date)] |
95 | | - (cljs-time.format/unparse thread-local-utc-date-format dt)))))) |
96 | | - |
97 | | -#?(:clj (def ^:private ^ThreadLocal thread-local-utc-timestamp-format |
98 | | - (proxy [ThreadLocal] [] |
99 | | - (initialValue [] |
100 | | - (doto (SimpleDateFormat. "yyyy-MM-dd'T'HH:mm:ss") |
101 | | - (.setTimeZone (TimeZone/getTimeZone "GMT")))))) |
102 | | - :cljs (def thread-local-utc-timestamp-format |
103 | | - (doto (cljs-time.format/formatter "yyyy-MM-dd'T'HH:mm:ss")))) |
| 95 | + #?(:clj |
| 96 | + #(.format ^SimpleDateFormat (.get thread-local-utc-date-format) %) |
| 97 | + :cljs |
| 98 | + (fn [input-date] |
| 99 | + (let [dt (from-date input-date)] |
| 100 | + (cljs-time.format/unparse thread-local-utc-date-format dt)))))) |
| 101 | + |
| 102 | +#?(:clj |
| 103 | + (def ^:private ^ThreadLocal thread-local-utc-timestamp-format |
| 104 | + (proxy [ThreadLocal] [] |
| 105 | + (initialValue [] |
| 106 | + (doto (SimpleDateFormat. "yyyy-MM-dd'T'HH:mm:ss") |
| 107 | + (.setTimeZone (TimeZone/getTimeZone "GMT")))))) |
| 108 | + :cljs |
| 109 | + (def thread-local-utc-timestamp-format |
| 110 | + (doto (cljs-time.format/formatter "yyyy-MM-dd'T'HH:mm:ss")))) |
104 | 111 |
|
105 | 112 | (def ^:private print-timestamp |
106 | 113 | (puget/tagged-handler |
107 | 114 | 'inst |
108 | | - #?(:clj #(str (.format ^SimpleDateFormat (.get thread-local-utc-timestamp-format) %) |
109 | | - (format ".%09d-00:00" (.getNanos ^Timestamp %))) |
110 | | - :cljs (fn [input-date] |
111 | | - (let [dt (from-date input-date)] |
112 | | - (cljs-time.format/unparse thread-local-utc-timestamp-format dt)))))) |
| 115 | + #?(:clj |
| 116 | + #(str (.format ^SimpleDateFormat (.get thread-local-utc-timestamp-format) %) |
| 117 | + (format ".%09d-00:00" (.getNanos ^Timestamp %))) |
| 118 | + :cljs |
| 119 | + (fn [input-date] |
| 120 | + (let [dt (from-date input-date)] |
| 121 | + (cljs-time.format/unparse thread-local-utc-timestamp-format dt)))))) |
113 | 122 |
|
114 | 123 | (def ^:private print-calendar |
115 | 124 | (puget/tagged-handler |
|
166 | 175 | 'cljs.core.uuid |
167 | 176 | (puget/tagged-handler 'uuid str)})) |
168 | 177 |
|
169 | | - |
170 | 178 | (defn- print-handler-resolver [extra-handlers] |
171 | 179 | (fn [^Class klz] |
172 | 180 | (and klz (get (merge @#'common-handlers @#'print-handlers extra-handlers) |
173 | 181 | (symbol (get-type-name klz)))))) |
174 | 182 |
|
175 | | -;; (defn register-print-handler! |
176 | | -;; "Register an extra print handler. |
| 183 | +#?(:clj |
| 184 | + (defn register-print-handler! |
| 185 | + "Register an extra print handler. |
177 | 186 |
|
178 | | -;; `type` must be a symbol of the fully qualified class name. `handler` is a |
179 | | -;; Puget handler function of two arguments, `printer` and `value`." |
180 | | -;; [type handler] |
181 | | -;; (alter-var-root #'print-handlers assoc type handler)) |
| 187 | + `type` must be a symbol of the fully qualified class name. `handler` is a |
| 188 | + Puget handler function of two arguments, `printer` and `value`." |
| 189 | + [type handler] |
| 190 | + (alter-var-root #'print-handlers assoc type handler))) |
182 | 191 |
|
183 | 192 | (defn puget-printer |
184 | 193 | ([] |
|
0 commit comments