0

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.

Julienknl
  • 11
  • 4
  • `clj-time` is a legacy library that wraps Joda-Time, but `start-date` is an instance of `java.time.LocalDateTime` which was introduced in Java 8, obsoleting Joda-Time. The [`clj-time` project status](https://github.com/clj-time/clj-time#project-status) summarises how you can move on from here. – Steffan Westcott Mar 31 '22 at 10:49
  • Thanks for the responses guys! And sorry for the confusion. I tested most of my functions using clj-time but it looks to be working. But I am still unsure what this implementation error means: No implementation of method: :to-date-time of protocol: #'clj-time.coerce/ICoerce? As I am a Swift based developer, does this mean that the method to-date-time should be implemented based on the protocol? – Julienknl Apr 04 '22 at 06:59

1 Answers1

0

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

Julienknl
  • 11
  • 4