Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for joda-time #47

Open
ikitommi opened this issue Aug 7, 2018 · 1 comment
Open

Support for joda-time #47

ikitommi opened this issue Aug 7, 2018 · 1 comment

Comments

@ikitommi
Copy link
Member

ikitommi commented Aug 7, 2018

For library ergonomics, would be great if there was bindings for joda-time classeses too. could be conditional, e.g. if the classes are found in classpath. Many libs (like https://github.com/metosin/metosin-common) still use joda...

(defmethod transform-type DateTime [_ _] {:type "string" :format "date-time"})
(defmethod transform-type LocalDate [_ _] {:type "string" :format "date"})
(defmethod transform-type LocalTime [_ _] {:type "string" :format "time"})
@ikitommi ikitommi changed the title Swagger + joda-time Support for joda-time Aug 7, 2018
@ikitommi
Copy link
Member Author

ikitommi commented Aug 7, 2018

also, coercion needs this too.

(defn ->DateTime [date] (if (instance? Date date) (tc/from-date date) date))

(defn parse-date-time ^DateTime [date] (tf/parse (tf/formatters :date-time-parser) (->DateTime date)))
(defn parse-date ^DateTime [date] (tf/parse-local-date (tf/formatters :date) (->DateTime date)))
(defn parse-time ^DateTime [date] (tf/parse-local-time (tf/formatters :time-parser) (->DateTime date)))

(defn cond-matcher [preds]
  (fn [x]
    (or
      (some
        (fn [[f1 f2]]
          (if (f1 x) (f2 x)))
        preds)
      x)))

(def string->joda
  {DateTime (cond-matcher {string? parse-date-time})
   LocalDate (cond-matcher {string? parse-date})
   LocalTime (cond-matcher {string? parse-time})})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant