Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClojureScript date-time library

I'd like to do some basic, but not very basic date-related operations on ClojureScript, like getting the days between two dates. There is clj-time which is a wrapper around Joda time, so it's Clojure only. I'm also aware of the date classes in Google Closure Library. There are many possibilites for JavaScript, see https://stackoverflow.com/questions/802861/javascript-date-manipulation-library or https://stackoverflow.com/questions/996995/javascript-date-time-library-recommendations. I wonder if there is an idiomatic ClojureScript way for this. If there is no such beast, I wonder which JavaScript library would be the best candidate for wrapping.

like image 922
Adam Schmideg Avatar asked Jun 11 '13 09:06

Adam Schmideg


2 Answers

Too late, but for those who come by search, there is cljs-time library.

like image 63
Ruslan Prokopchuk Avatar answered Oct 15 '22 08:10

Ruslan Prokopchuk


http://momentjs.com is easy to use for date arithmetic.

For example, the difference between two dates, in number of days:

(defn mom []
  (let [log (fn [& args] (.log js/console (apply str args)))
        days-ago (fn [n] (.subtract (js/moment) "days" n))]
    (log {:difference (.diff (days-ago 7) (days-ago 28) "days")})))

(mom) ==> {:difference 21}
like image 11
jbouwman Avatar answered Oct 15 '22 06:10

jbouwman