Fork me on GitHub

How do I manipulate #inst values? Calculate interval b/w two instants, compare time intervals and so on.


@jaihindh.reddy You will want to look at Java Time for stuff like that I suspect.


I'm writing a script that takes data from a SQL database and ssh into servers, grep and parse logs....


^ The new java time thing? I see various names floating around, java.time, clojure.time, clojure.instant, joda etc and don't know what the consensus is (or if there is one)


java time seems to be good upon glancing the API. No blunders like mutable dates ๐Ÿ™‚


Java Time is the "standard" way to do that sort of stuff ever since Java 8.


It replaces Joda Time.

๐Ÿ‘ 4

You might find the wrapper easier to work with than raw Java interop.


@ahmed1hsn I concur with @dpsutton That code compiles without error for me too -- so something you have at line 100 is where the error likely is, in your file, not in the 62 lines that come from that money.clj script.


This code can't catch first exception But when I execute (redis/ping), it raise up this exception


because carmine is a pain


(I maybe be confusing carmine with faraday)


(assuming that is the redis library you are using)


@seancorfield i still think java time has an insufficient spec for interval types compared to joda time ;_;


@sova I'm sure Stephen Colebourne has a good reason for that difference...


(and there's always his org.threeten/threeten-extra library with etc)


Ah! that's right. i forgot about the "extras" library


now that's what i'm talking about. thank you.


hey guys, i am trying to generate the war file of my compojure-api project but it keep generating a jar. help? please.


it's an api


@hiredman I checked out that link source code, still don't understand why can't capture that exception.


I always have trouble using require the first time I add a new lib. The namespace name isn't always same as the artifact name or the library name. Can I reliably find this information (which nses it has) from the artifact itself somehow knowing just the :mvn/version of it without relying on documentation. Because once I require it, I can mostly be self sufficient using the stuff in clojure.repl (`find-doc`, doc, source et al)

Alex Miller (Clojure team)13:12:38

Unfortunately the honest answer is no. There is no relationship between an artifact group/name/version and the namespaces in it.

๐Ÿ‘ 4
๐Ÿ˜ 4

how to toggle class via :on-click in cljs?

eccentric J06:12:41

What libraries or frameworks are you using in cljs?


which includes hiccup more or less

eccentric J07:12:35

Forgive me if Iโ€™m unhelpful here but I would suspect combined with a function to take relevant state and return a string of class names?

eccentric J07:12:42

(defn get-classes
  (->> (keep some? ["my-class"
                    (when active? "active")])
       clojure.string/join " "))


1. Is there a way to configure to return java.time.Instants instead of java.sql.Timestamps? 2. Is there a way to make Clojure print java.time.Instants with #inst? 3. Is there a way to make Clojure read #insts as java.time.Instants? 4. Are the above bad ideas?

Alex Miller (Clojure team)17:12:40

Re 2, it should already do that with Java 8+

Alex Miller (Clojure team)17:12:42

They are good ideas, but 3 would likely be a breaking change for some


Thank you for your suggestion! I have looked at Joda time, and it seems like java.time largely replaces all other time stuff in the Java world, making the go-to idiomatic Clojure wrapper of java.time. I was just trying to have minimal deps while also minimizing the amount of interop code.


you can coerce to and from SQL timestamps with clj-time.coerce


there should also be protocol extension in clj-time.jdbc for automatic coercion


this converts to/from joda-time though but usually that's not an issue


Hi, friendly people. My question is somewhat n00b annoyance about organisation of namespace and project in general. According to Clojure namespace evaluation, it does read from top to bottom. Which means in normal case, the function have to be defined before it can be used. But that leads that my most abstract and high-level functions are at the bottom of file, and I can't program top-down. Looks like, the most generic functions like main game loop literary is the last function at the very bottom of my file. Is it as it supposed to be? I know one can declare functions ahead, but that sux.


How do you deal mentally with this rading text file from bottom?


Or the solution is divide namespaces by abstraction... most generic functions in one namespace which requires other namespaces? So it seems that programming would be like writing main function, fill it up with smaller functions, then extract those into another namespace and require :all that namespace


i generally end up putting common/utility functions at the top and dividing out into more namespaces based what seems like a logical organization


so if I end up needing a utility function in several namespaces I'll make a utils namespace and require that everywhere for example


code organization in a purely functional language will generally be a looser than object-oriented languages though


then my main namespaces are named & divided according to what functionality they provide, f.ex. formatters, imports, exports, user, sql, etc. etc.


then try and keep namespaces short enough to be able to mentally "contain" them while working, which for me seems to be 2-300 codelines pr. namespace max


Using I'm unable to do this simple thing: Given a java.time.Instant t, find the hour(s) the time range t-e to t+e falls on, where e is an epsilon value. For example, for t = "today 15:56" and e = "5 minutes" t-e would be "today 15:51" and t+e would be "today 16:01" making the output of the hypothetical function ["today 15" "today 16"]. How can I accomplish this?


@jaihindh.reddy Have you looked at org.threeten/threeten-extra ? It has Intervals and a contains? function that might be helpful. This extra lib is mentioned at


@dorab Thanks! This is exactly what I was looking for...

(defn record->hours
  [epsilon {:keys [addedon updatedon] :as record}]
  "Returns a seq of all hours that might have encompassed all activity in a DB record"
  (let [max-time (t/truncate-to (t/minus addedon epsilon) :hours)
        min-time (t/truncate-to (t/plus updatedon epsilon) :hours)]
    (->> (t/iterate t/plus min-time (t/duration 1 :hours))
         (take-while #(not (t/after? % max-time))))))

eccentric J23:12:57

Is there a recommended way to make this less verbose?

clj -A:repl -m nrepl.cmdline --interactive
Could I just toss that in a


you could add the main nrepl.cmdline to an alias I think?


but I just use a couple of functions in my bash_profile / zshrc, yeah

eccentric J23:12:02

{:aliases {:repl {:extra-deps {nrepl/nrepl {:mvn/version "0.5.3"}
                               proto-repl {:mvn/version "0.3.1"}}
                  :main-opts ["-m nrepl.cmdline --interactive"]}}}
Usage: clj -A:repl Works great, thanks!


if you don't use keyboard shortcuts for searching your shell history, you should. it is way better then using shell aliases / functions and keeping those things updated

eccentric J23:12:15

Thatโ€™s a good point. I just started using fish shell which provides a lot of that automatically, but I felt like I was missing something about deps.edn.