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.
Too late, but for those who come by search, there is cljs-time library.
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}
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