|
5 | 5 | [puget.dispatch] |
6 | 6 | [puget.printer :as puget] |
7 | 7 | [arrangement.core] |
8 | | - [lambdaisland.deep-diff.diff :as diff])) |
| 8 | + [lambdaisland.deep-diff.diff :as diff]) |
| 9 | + (:import (java.text SimpleDateFormat) |
| 10 | + (java.util TimeZone) |
| 11 | + (java.sql Timestamp))) |
9 | 12 |
|
10 | 13 | (defn print-deletion [printer expr] |
11 | 14 | (let [no-color (assoc printer :print-color false)] |
|
34 | 37 | [:align (interpose [:span (:map-delimiter this) :line] entries)] |
35 | 38 | (color/document this :delimiter "}")])) |
36 | 39 |
|
| 40 | +(def ^:private ^ThreadLocal thread-local-utc-date-format |
| 41 | + (proxy [ThreadLocal] [] |
| 42 | + (initialValue [] |
| 43 | + (doto (SimpleDateFormat. "yyyy-MM-dd'T'HH:mm:ss.SSS-00:00") |
| 44 | + (.setTimeZone (TimeZone/getTimeZone "GMT")))))) |
| 45 | + |
| 46 | +(def ^:private print-date |
| 47 | + (puget/tagged-handler |
| 48 | + 'inst |
| 49 | + #(.format ^SimpleDateFormat (.get thread-local-utc-date-format) %))) |
| 50 | + |
| 51 | +(def ^:private ^ThreadLocal thread-local-utc-timestamp-format |
| 52 | + (proxy [ThreadLocal] [] |
| 53 | + (initialValue [] |
| 54 | + (doto (SimpleDateFormat. "yyyy-MM-dd'T'HH:mm:ss") |
| 55 | + (.setTimeZone (TimeZone/getTimeZone "GMT")))))) |
| 56 | + |
| 57 | +(def ^:private print-timestamp |
| 58 | + (puget/tagged-handler |
| 59 | + 'inst |
| 60 | + #(str (.format ^SimpleDateFormat (.get thread-local-utc-timestamp-format) %) |
| 61 | + (format ".%09d-00:00" (.getNanos ^Timestamp %))))) |
| 62 | + |
| 63 | +(def ^:private print-calendar |
| 64 | + (puget/tagged-handler |
| 65 | + 'inst |
| 66 | + #(let [formatted (format "%1$tFT%1$tT.%1$tL%1$tz" %) |
| 67 | + offset-minutes (- (.length formatted) 2)] |
| 68 | + (str (subs formatted 0 offset-minutes) |
| 69 | + ":" |
| 70 | + (subs formatted offset-minutes))))) |
| 71 | + |
37 | 72 | (def ^:private print-handlers |
38 | 73 | {'lambdaisland.deep_diff.diff.Deletion |
39 | 74 | print-deletion |
|
72 | 107 | [:span |
73 | 108 | (puget/format-doc printer k) |
74 | 109 | (if (coll? v) (:map-coll-separator printer) " ") |
75 | | - (puget/format-doc printer v)]))))}) |
| 110 | + (puget/format-doc printer v)])))) |
| 111 | + |
| 112 | + 'java.util.Date |
| 113 | + print-date |
| 114 | + |
| 115 | + 'java.util.GregorianCalendar |
| 116 | + print-calendar |
| 117 | + |
| 118 | + 'java.sql.Timestamp |
| 119 | + print-timestamp |
| 120 | + |
| 121 | + 'java.util.UUID |
| 122 | + (puget/tagged-handler 'uuid str)}) |
76 | 123 |
|
77 | 124 | (defn- print-handler-resolver [extra-handlers] |
78 | 125 | (fn [^Class klz] |
|
0 commit comments