A clojure newbie question. I am trying to figure out the best way to pass a date from a client (written in any language) to a server written in clojure that rests on a Datomic database. To avoid any problems with language specific classes I was planning to pass the date as a RFC3339 formatted string. However, I'm having trouble parsing the string in Clojure. My, apparently erroneous, assumption was that I could do:
(clojure.instant/parse-timestamp "2014")
and thus get an instant. However, this call results in
clojure.lang.ArityException: Wrong number of args (1) passed to: instant$fn--6183$fn …
This confuses me greatly since as far as I can see this function only takes a single argument (formatted string).
What have I missed?
parse-timestamp is a function of two arguments. The string representation of a timestamp is the second one. The first one is for passing in a function that takes a bunch of arguments and constructs an object representing an instant. The arguments to this new-instant function are described in the docstring of parse-timestamp -- see (doc clojure.instant/parse-timestamp) for details.
Normally you don't need to call parse-timestamp directly, as clojure.instant exports a bunch of functions for reading in timestamps:
(clojure.instant/read-instant-date "2014-04-23T10:13Z")
;= #inst "2014-04-23T10:13:00.000-00:00"
read-instant-calendar and read-instant-timestamp are the other two functions of this type. They're all built using parse-timestamp and have docstrings documenting their contracts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With