This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-05-12
Channels
- # aleph (6)
- # announcements (11)
- # babashka (24)
- # beginners (127)
- # calva (33)
- # chlorine-clover (5)
- # cider (7)
- # clara (9)
- # cljs-dev (54)
- # cljsrn (5)
- # clojure (61)
- # clojure-australia (8)
- # clojure-bay-area (11)
- # clojure-europe (36)
- # clojure-italy (3)
- # clojure-nl (3)
- # clojure-spec (6)
- # clojure-taiwan (1)
- # clojure-uk (8)
- # clojurescript (94)
- # code-reviews (2)
- # community-development (6)
- # conjure (26)
- # core-typed (1)
- # cursive (3)
- # datahike (4)
- # datomic (14)
- # events (1)
- # graphql (1)
- # honeysql (49)
- # introduce-yourself (5)
- # jobs-discuss (15)
- # kaocha (6)
- # lsp (8)
- # malli (1)
- # meander (5)
- # nrepl (1)
- # off-topic (21)
- # other-languages (1)
- # pathom (13)
- # podcasts (1)
- # polylith (1)
- # reitit (16)
- # shadow-cljs (50)
- # spacemacs (11)
- # sql (11)
- # tools-deps (21)
- # unrepl (1)
- # vim (9)
I'm still trapped in how to coerce a string datetime in iso format to a java.util.Date
or something similar, in my requests with reitit and ring, can somebody help please? 😢
you could try functions from the core - https://clojuredocs.org/clojure.instant
my problem isn't exactly the conversion per se, but how to use it with coerce request middleware
because it is already coercing the request to basic data, but I don't know how to make it recognize that a json field is a date and use some function to coerce it
tried to follow how reitit works internally in reitit.ring.coercion.coerce-request-middleware
with reitit.coercion.schema
but couldn't understand how reitit get the matchers in order to call schema.coerce.coercer
, I think I can just use schema-tools.coerce/json-coercion-matcher
that will work, in the coercer
call, but I don't know how to configure this in the middleware exaclty
;; ISO_OFFSET_DATE_TIME format, e.g., 2011-12-03T10:15:30+01:00 or 2011-12-03T10:15:30Z
(defn ^:private date-time-parser
[date-time]
(try
(.parse DateTimeFormatter/ISO_OFFSET_DATE_TIME date-time)
(catch DateTimeParseException _
nil)))
(def date-range [:map
{:closed true}
[:from {:optional true} [:fn {:swagger/type "string" :swagger/format "date-time" :error/message iso8601-message} date-time-parser]]
[:to {:optional true} [:fn {:swagger/type "string" :swagger/format "date-time" :error/message iso8601-message} date-time-parser]]])
(def ^:private iso8601-message "is not in ISO DATE TIME format, e.g. 2020-07-03T10:15:30+01:00 or 2020-07-03T10:15:30Z")
hmm where do you use date-range
?
:post {:handler (start app-config)
:parameters {:body specs/start}
:swagger {:produces [blah-blah-version]}}}]
I'll try to check how malli works to see if I can adapt this to schema