Open ikitommi opened 6 years ago
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})})
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...