Clojure using instant / syntax markup

A clojure newbie question. I am trying to find the best way to transfer the date from a client (written in any language) to a server written in clojure, which relies on the Datomic database. To avoid problems with language classes, I planned to pass the date as a formatted string RFC3339. However, I had a problem parsing a string in Clojure. My apparently erroneous assumption was that I could do:

(clojure.instant/parse-timestamp "2014")

and thus get a moment. However, this call leads to

clojure.lang.ArityException: Wrong number of args (1) passed to: instant$fn--6183$fn

This bothers me a lot because, as far as I can see, this function takes only one argument (formatted string).

What did I miss?

+4
source share
1 answer

parse-timestampis a function of two arguments. The string representation of the timestamp is the second. The first is to be passed to a function that takes a bunch of arguments and creates an object that represents the instant. The arguments for this function are new-instantdescribed in docstring parse-timestamp- see (doc clojure.instant/parse-timestamp)for details.

Usually you do not need to call directly parse-timestamp, as it clojure.instantexports a bunch of functions to read in timestamps:

(clojure.instant/read-instant-date "2014-04-23T10:13Z")
;= #inst "2014-04-23T10:13:00.000-00:00"

read-instant-calendarand read-instant-timestamp- two other functions of this type. All of them are built using parse-timestampand have documents documenting their contracts.

+10
source

Source: https://habr.com/ru/post/1537642/


All Articles