juxt

2020-05-03T00:04:02.127200Z

got something going :

(deftype DateHandler []
  Object
  (tag [_ v] "time/date")
  (rep [_ v] (with-out-str (print v)))
  (stringRep [_ v] nil))
(def date-reader (t/reader :json {:handlers {"time/date" #(cljs.reader/read-string %)}}))
(def date-writer (t/writer :json {:handlers {tutil/Date (DateHandler.)}}))
(t/read date-reader (t/write date-writer (ti/today)))

2020-05-03T01:30:14.128Z

(def Date (type (t/date)))
(def DateTime (type (t/date-time)))
(def Time (type (t/time)))
(def Period (type (t/new-period 1 :days)))
(def Duration (type (t/new-duration 1 :seconds)))
(def Instant (type (t/instant)))

(deftype TickHandler []
  Object
  (tag [_ v] "time/tick")
  (rep [_ v] (with-out-str (print v)))
  (stringRep [_ v] nil))

(def tick-handler (TickHandler.))

(def tick-handler-map
  (into {}
    (map #(vector (first %) (second %))
      (partition 2
        (interleave
          [Date DateTime Time Period Duration Instant]
          (repeat tick-handler))))))
this is working for the clojurescript side

2020-05-03T03:03:05.128500Z

got round trip working 😄

(:require
  #?(:cljs [cljs.reader] 
     :clj [clojure.edn])
  [time-literals.read-write :as rw]
  [cognitect.transit :as tr]
  [tick.alpha.api :as t])

(def transit-tag "time/tick")

#?(:cljs (deftype TickHandler []
           Object
           (tag [_ v] transit-tag)
           (rep [_ v] (with-out-str (pr v)))
           (stringRep [_ v] nil)))

(def tick-transit-write-handler
  #?(:cljs (TickHandler.)
     :clj (tr/write-handler
            transit-tag
            (fn [v] (with-out-str (pr v))))))

(def tick-transit-writer-handler-map
  (reduce
    (fn [m [k v]] (assoc m k v))
    {}
    (partition 2
      (interleave
        [Date DateTime Time Period Duration Instant]
        (repeat tick-transit-write-handler)))))

(def tick-transit-reader
  {transit-tag
   #?(:cljs cljs.reader/read-string
      :clj (tr/read-handler #(clojure.edn/read-string {:readers rw/tags} %)))})

🎉 1