Skip to content

Commit c970691

Browse files
author
awb99
committed
fipp with zoneddatetime
1 parent 8fed0ca commit c970691

File tree

11 files changed

+126
-55
lines changed

11 files changed

+126
-55
lines changed

demo/deps.edn

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{:paths ["src"]
2+
:deps
3+
{org.clojure/clojure {:mvn/version "1.11.3"}
4+
org.pinkgorilla/modular {:local/root ".." :deps/manifest :deps}}
5+
6+
:aliases
7+
{:demo-log-default
8+
{:extra-paths ["demo"]
9+
:exec-args {:custom-config false}
10+
:exec-fn logging/demo}
11+
12+
:demo-log-custom
13+
{:extra-paths ["demo"]
14+
:exec-args {:custom-config true}
15+
:exec-fn logging/demo}
16+
17+
;; SYSTEM RUNNER DEMOS
18+
19+
:demo-config
20+
{:extra-paths ["demo" "test/resources" "test/src"]
21+
:exec-args {:custom-config true}
22+
:exec-fn config/demo}
23+
24+
:demo-system ; run a system with deps.edn: clj -X:demo-system :run '[1 2 3]'
25+
{:extra-deps {nrepl/nrepl {:mvn/version "0.9.0"}}
26+
:extra-paths ["src-demo" "test/resources" "test/src"]
27+
:exec-fn modular.system/start!
28+
:exec-args {:services "services.edn"
29+
:config ["webly/config.edn" {:ns-clj [demo.super]}]}}
30+
31+
:run {:exec-args {:run demo.run/run27}}
32+
33+
:demo-system-main
34+
{:extra-deps {nrepl/nrepl {:mvn/version "0.9.0"}}
35+
:extra-paths ["src-demo" "test/resources" "test/src"]
36+
:main-opts ["-m" "modular.system"
37+
"--services" "services.edn"
38+
"--config" "[\"webly/config.edn\" ]"]}
39+
40+
; tree and list are here just because tools.deps.alpha does not work on my machine
41+
;:tree {:extra-deps {org.clojure/tools.deps.alpha {:mvn/version "0.14.1178"}}
42+
; :exec-fn clojure.tools.cli.api/tree}
43+
;:list {:extra-deps {org.clojure/tools.deps.alpha {:mvn/version "0.14.1178"}}
44+
; :exec-fn clojure.tools.cli.api/list}
45+
46+
:nrepl
47+
{:extra-deps {nrepl/nrepl {:mvn/version "0.8.3"}
48+
cider/cider-nrepl {:mvn/version,"0.27.2"}
49+
cider/piggieback {:mvn/version "0.4.2"}}
50+
:main-opts ["-m" "nrepl.cmdline"
51+
"-b" "0.0.0.0"
52+
"-p" "9100"
53+
;"--middleware" "[cider.nrepl/cider-middleware,refactor-nrepl.middleware/wrap-refactor]"
54+
]}}}
File renamed without changes.

demo/src/demo/fipp.clj

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
(ns demo.fipp
2+
(:require
3+
[modular.fipp :refer [pprint-str]]
4+
[tick.core :as t]))
5+
6+
(def data
7+
{:a 1
8+
:b [1 2 3]
9+
:c [1.0 2.0 3.0]
10+
:inst (t/instant)
11+
:zdt (t/zoned-date-time)})
12+
13+
data
14+
;; => {:a 1,
15+
;; :b [1 2 3],
16+
;; :c [1.0 2.0 3.0],
17+
;; :inst #time/instant "2024-10-11T17:18:54.857927482Z",
18+
;; :zdt #time/zoned-date-time "2024-10-11T12:18:54.858196816-05:00[America/Panama]"}
19+
20+
(-> data pr-str read-string)
21+
;; => {:a 1,
22+
;; :b [1 2 3],
23+
;; :c [1.0 2.0 3.0],
24+
;; :inst #time/instant "2024-10-11T17:18:54.857927482Z",
25+
;; :zdt #time/zoned-date-time "2024-10-11T12:18:54.858196816-05:00[America/Panama]"}
26+
27+
(-> data pprint-str read-string)
28+
;; => {:a 1,
29+
;; :b [1 2 3],
30+
;; :c [1.0 2.0 3.0],
31+
;; :inst #time/instant "2024-10-11T17:18:54.857927482Z",
32+
;; :zdt #time/zoned-date-time "2024-10-11T12:18:54.858196816-05:00[America/Panama]"}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

deps.edn

-51
Original file line numberDiff line numberDiff line change
@@ -86,56 +86,5 @@
8686
; :build-cljs-test
8787

8888

89-
:demo-log-default
90-
{:extra-paths ["demo"]
91-
:exec-args {:custom-config false}
92-
:exec-fn logging/demo}
93-
94-
:demo-log-custom
95-
{:extra-paths ["demo"]
96-
:exec-args {:custom-config true}
97-
:exec-fn logging/demo}
98-
99-
;; SYSTEM RUNNER DEMOS
100-
101-
:demo-config
102-
{:extra-paths ["demo" "test/resources" "test/src"]
103-
:exec-args {:custom-config true}
104-
:exec-fn config/demo}
105-
106-
:demo-system ; run a system with deps.edn: clj -X:demo-system :run '[1 2 3]'
107-
{:extra-deps {nrepl/nrepl {:mvn/version "0.9.0"}}
108-
:extra-paths ["src-demo" "test/resources" "test/src"]
109-
:exec-fn modular.system/start!
110-
:exec-args {:services "services.edn"
111-
:config ["webly/config.edn" {:ns-clj [demo.super]}]}}
112-
113-
:run {:exec-args {:run demo.run/run27}}
114-
115-
:demo-system-main
116-
{:extra-deps {nrepl/nrepl {:mvn/version "0.9.0"}}
117-
:extra-paths ["src-demo" "test/resources" "test/src"]
118-
:main-opts ["-m" "modular.system"
119-
"--services" "services.edn"
120-
"--config" "[\"webly/config.edn\" ]"
121-
]}
122-
123-
; tree and list are here just because tools.deps.alpha does not work on my machine
124-
;:tree {:extra-deps {org.clojure/tools.deps.alpha {:mvn/version "0.14.1178"}}
125-
; :exec-fn clojure.tools.cli.api/tree}
126-
;:list {:extra-deps {org.clojure/tools.deps.alpha {:mvn/version "0.14.1178"}}
127-
; :exec-fn clojure.tools.cli.api/list}
128-
129-
130-
:nrepl
131-
{:extra-deps {nrepl/nrepl {:mvn/version "0.8.3"}
132-
cider/cider-nrepl {:mvn/version,"0.27.2"}
133-
cider/piggieback {:mvn/version "0.4.2"}}
134-
:main-opts ["-m" "nrepl.cmdline"
135-
"-b" "0.0.0.0"
136-
"-p" "9100"
137-
;"--middleware" "[cider.nrepl/cider-middleware,refactor-nrepl.middleware/wrap-refactor]"
138-
]}
139-
14089
;
14190
}}

src/modular/encoding/fipp.clj

+23-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,34 @@
22
(:require
33
[time-literals.data-readers] ;; For literals
44
[time-literals.read-write] ;; For printing/writing
5-
[fipp.ednize]))
5+
[fipp.ednize])
6+
(:import
7+
[java.time Period
8+
LocalDate
9+
LocalDateTime
10+
ZonedDateTime
11+
OffsetTime
12+
Instant
13+
OffsetDateTime
14+
ZoneId
15+
DayOfWeek
16+
LocalTime
17+
Month
18+
Duration
19+
Year
20+
YearMonth
21+
MonthDay]))
622

723
(extend-protocol fipp.ednize/IEdn
8-
java.time.LocalDate
24+
LocalDate
925
(fipp.ednize/-edn [x]
1026
(tagged-literal 'time/date (str x)))
11-
java.time.LocalDateTime
27+
LocalDateTime
1228
(fipp.ednize/-edn [x]
1329
(tagged-literal 'time/date-time (str x)))
14-
java.time.Instant
30+
ZonedDateTime
31+
(fipp.ednize/-edn [x]
32+
(tagged-literal 'time/zoned-date-time (str x)))
33+
Instant
1534
(fipp.ednize/-edn [x]
1635
(tagged-literal 'time/instant (str x))))

src/modular/fipp.clj

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(ns modular.fipp
2+
(:require
3+
[modular.encoding.fipp] ; side-effects
4+
[fipp.clojure])
5+
(:import
6+
[java.io StringWriter]))
7+
8+
; redirect std out is NOT a good idea in an edn writer
9+
; because every console output will be printed to the edn doucment
10+
(defn pprint [data opts]
11+
(with-out-str
12+
(fipp.clojure/pprint data opts)))
13+
14+
(defn pprint-str [data]
15+
(let [sw (StringWriter.)]
16+
(fipp.clojure/pprint data {:width 60 :writer sw :print-meta true})
17+
(str sw)))

0 commit comments

Comments
 (0)