dm3 / clojure.java-time

Java 8 Date-Time API for Clojure
MIT License
468 stars 47 forks source link

java.lang.RuntimeException: No reader function for tag object #15

Open sooheon opened 6 years ago

sooheon commented 6 years ago

The java.time.foo objects that are returned by fns in this lib print as something like #object[java.time.Instant "0x6cc2abad" "2017-11-13T01:40:56.483Z"]

However these can't be used interactively as data because unlike java.util.Date's #inst "2017-11-13T01:41:43.571-00:00", the repl explodes when given the java.time.Instant object. Since it complains about having no reader function for #object, I guess it's a matter of extending edn to recognize #objects.

Have you encountered this problem? Is this sth for this library to tackle, or for each end user to roll their own?

dm3 commented 6 years ago

The objects of java.time.* type are printed as any other object because core Clojure only defines the #inst print method for java.util.Date/util.Calendar/sql.Timestamp. It also only defines an #inst data reader which reads into java.util.Date by default.

Given that the Java-Time library handles Clojure integration with the java.time package, we could provide readers for the most commonly used java.time types. We could define data readers which would parse the most precise default formatted representations of time entites back into the java.time objects, e.g.:

etc.

I don't see problems with defining those, given we namespace the data reader tags. It could potentially conflict with someone who already defined the same data readers - in that case they could continue to use the previous version of the library.

Printing the java.time types into their "readable" representations is trickier. This is a significant change in the behaviour which might cause breakage. However, I'm pretty sure many people would love to be able to treat the java.time as EDN-serializable objects so I'm interested in introducing either:

what do you think? Would you be willing to contribute an implementation?

magnars commented 5 years ago

If you're still interested, here's a library that adds readers and printers for java.time classes: https://github.com/magnars/java-time-literals

henryw374 commented 3 years ago

And another.. https://github.com/henryw374/time-literals