I like ClojureScript, but to interop between CLJS and Javascript is difficult. I would like to create a function that can perform date culculations in arbitrary units, such as the following. But this code results in errors. Is it not possible to treat JS methods like .foo like functions?
(defn date-add [date num unit]
(let [[getter setter]
(case unit
:sec [.getSeconds .setSeconds]
:min [.getMinutes .setMinutes]
:hour [.getHours .setHours]
:day [.getDate .setDate]
:month [.getMonth .setMonth]
:year [.getFullYear .setFullYear])]
;; such as (.setDate date (+ num (.getDate date)))
(setter date (+ num (getter date)))
(js/Date. (.getTime date))))
Though I know great libraries like deja-fu or cljs-time, the avobe is the example. I would like to be able to perform simple operations on dates without using a library.
I think this gives you a path (I'm not convinced it's great):