Skip to content

Predicate for when something is a date time type #13

@lvh

Description

@lvh

I have a nested data structure and I want to convert all the date time objects in it to ISO8601 timestamps during serialization. So, I need to find out what the timestamps are. I can't just try converting with instant, because it'll try to convert strings, which I don't want.

inst? is almost what I want, but Joda Time instances don't satisfy Inst. This could be solved with something along the lines of the following:

(try
  (Class/forName "org.joda.time.Instant")
  (eval
   '(extend-protocol Inst
      org.joda.time.Instant
      (inst-ms* [inst] (inst-ms* (jt/instant inst)))

      org.joda.time.DateTime
      (inst-ms* [inst] (inst-ms* (jt/instant inst)))))
  (catch ClassNotFoundException cnfe))

(though this project already has a better when-joda macro :))

Do you have a preferred solution?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions