So I have a bunch of blocks with from:: and to:: properties, formatted as hh:mm. I’m trying to figure out how to do some arithmetic with those, specifically, calculate duration. I tried
(- (:to properties) (:from properties))
in the view, which results in NaN. The same with “+” results in the times being concatenated, so obviously, they are strings. I have never touched cljs before. I just seem to get the basic idea because I learned Lisp in school as a teenager.
How would I go about getting the properties converted into times that I can use for calculations?
Got something but it doesn’t look pretty, especially the output…
(int (/
(-
(+ (* (int (subs (:to properties) 0 2)) 60) (int (subs (:to properties) 3 5)) )
(+ (* (int (subs (:from properties) 0 2)) 60) (int (subs (:from properties) 3 5)) )
)
60))
":"
(mod
(-
(+ (* (int (subs (:to properties) 0 2)) 60) (int (subs (:to properties) 3 5)) )
(+ (* (int (subs (:from properties) 0 2)) 60) (int (subs (:from properties) 3 5)) )
)
60)
Is there a way to format number output, like limit decimals or force leading zeros?
When parsing strings, consider using clojure.string/split
1 Like