Fork me on GitHub
#clojurescript
<
2019-07-14
>
Justin Duncan07:07:24

does anyone know how to get the DateTime from a json+transit encoded string?

Justin Duncan07:07:24

It looks like this:

[TaggedValue: LocalDateTime, 2019-07-14T00:06:25.433]
. I have tried various routes including using cognitec/transit but I can't seem to get this date out. Please help

Crispin16:07:58

on the clojure side, or the clojurescript side?

Crispin16:07:39

I have custom readers/writers

Crispin16:07:49

on the cljs side:

Crispin16:07:28

(:import [goog.date DateTime])
...
(def goog-utc-writer
  (t/write-handler
   (constantly "m")
   #(.getTime %)
   #(str (.getTime %))))

(def json-reader (t/reader :json {:handlers {cljs.core/Keyword (t/KeywordHandler.)
                                      goog.date.UtcDateTime goog-utc-writer
                                      goog.date.DateTime goog-utc-writer}}))
(def json-writer (t/writer :json {:handlers {cljs.core/Keyword (t/KeywordHandler.)
                                      goog.date.UtcDateTime goog-utc-writer
                                      goog.date.DateTime goog-utc-writer}}))

Crispin16:07:44

and use those readers and writers in the transit calls

Crispin16:07:50

on the clj side I have

Crispin16:07:39

(def joda-time-writer
  (t/write-handler
   (constantly "m")
   #(-> % coerce/to-date .getTime)
   #(-> % coerce/to-date .getTime .toString)))

(def writer (t/writer out :json
                         {:handlers {org.joda.time.DateTime joda-time-writer}}))

Crispin16:07:50

hope that helps you out

👍 4
metehan12:07:44

Did anyone tried to run clojurescript inside phonegap? I couldn't find any sample on github.

David Pham20:07:46

Maybe not ClojureScript specific question, but anyone has some insights on using web workers? Are they good/bad ideas? What are the rookie mistakes with them?

David Pham20:07:29

I have looked Butler and Servant as library, but I wanted to know what kind of problems I could get into when I use them :)