Fork me on GitHub
#reitit
<
2018-11-30
>
ikitommi06:11:59

for Java8 dates, I think they could be supported oob, as Jsonista does it for JSON and Java8 is required anyway, wrote: https://github.com/metosin/muuntaja/issues/92

ikitommi06:11:11

PR would be welcome!

✌️ 4
kanwei20:11:28

@ikitommi thanks, I actually dug into the transit-clj implementation and it basically wraps around transit-java, which seems to hardcode a lot of mappings. Since transit is supposed to be extendable, should we be doing something like this? https://blog.klipse.tech/clojure/2016/09/22/transit-clojure-2.html

kanwei20:11:53

not sure where "transit-dates/readers" is coming from in your docs

ikitommi21:11:53

@kanwei exactly. The example was kinda bad, as the readers & writers were not explained. But those are the maps from the tutorial.

ikitommi21:11:18

something like (joda example):

(ns metosin.transit.dates
  "Transit readers and writers for JodaTime and goog.date.
  Supports two types:
  - DateTime (org.joda.time.DateTime, goog.date.UtcDateTime)
  - LocalDate (org.joda.time.LocalDate, goog.date.Date)
  Represents DateTimes in RFC 3339 format: yyyy-mm-ddTHH:MM:SS.sssZ.
  RFC 3339 format is an specific profile of ISO 8601 DateTime format.
  Some consideration has been made to provide performant read
  implemenation for ClojureScript."
  (:require [cognitect.transit :as transit]
            [metosin.dates :as d]))

(def writers
  {#?(:clj org.joda.time.DateTime, :cljs goog.date.UtcDateTime)
   (transit/write-handler (constantly "DateTime") d/to-string)

   #?(:clj org.joda.time.LocalDate, :cljs goog.date.Date)
   (transit/write-handler (constantly "Date") d/to-string)})

(def readers
  ; 1 argument arity version must be explicitly used for clojurescript
  {"DateTime" (transit/read-handler #(d/date-time %))
   "Date"     (transit/read-handler #(d/date %))})