Clojure instant/parse-timestamp usage
Asked Answered
L

1

6

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?

Luck answered 23/4, 2014 at 7:36 Comment(2)
Just noticed that parse-timestamp is a variable not a function. But I still wonder how it's used to parse a string.Luck
Global functions live in vars. See def. defn is based on def.Michikomichon
U
13

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.

Unstudied answered 23/4, 2014 at 8:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.