'ICoerce produces protocol error for to-date-time
I took over a Clojure project and I am experiencing an error as follows:
No implementation of method: :to-date-time of protocol: #'clj-time.coerce/ICoerce found for class: java.time.LocalDateTime
Where I am trying to assign a value in here:
{ :start-date (time/to-string start-date) }
I am using clj-time as a dependency.
What I am confused about is especially the part where it says No implementation of method: :to-date-time of protocol even though I am using time/to-string
Is there a way I need to add that protocol?
Your help will be much more appreciated.
Solution 1:[1]
I resolved this issue. MYSQL 8 connector was returning Java LocalDateTime and clj-time was trying to convert this LocalDateTime into Joda Date time which does not exists in Java 8
I had to import those:
(:import [java.time LocalDateTime]
[java.time.format DateTimeFormatter])
Create the formatter:
(def formatter (DateTimeFormatter/ofPattern "yyyy-MM-dd HH:mm:ss"))
And then convert to string:
(defn date-parser [{:keys [start-date expiry-date]}]
{:start-date (.toString (.format start-date formatter))
:expiry-date (.toString (.format expiry-date formatter))})
Special thanks to Steffan Westcott and Alan Thompson
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Julienknl |
