Created
December 17, 2014 15:48
-
-
Save wunki/3b63ca34e882a9584491 to your computer and use it in GitHub Desktop.
Get the last weeks in Clojure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn get-weeks [n] | |
"Returns a vector of dictionaries containing the start and end days of the last n weeks" | |
(let [now (t/today-at-midnight) | |
this-day-num (Integer. (f/unparse (f/formatter "e") now)) | |
last-monday (t/minus now (t/days (dec this-day-num))) | |
span-fn (fn [v w] | |
(let [monday (t/minus last-monday (t/weeks w)) | |
sunday (t/plus monday (t/days 7)) | |
week (Integer. (f/unparse (f/formatter "w") monday))] | |
(conj v {:week week | |
:monday monday | |
:sunday sunday})))] | |
(reduce span-fn [] (range n)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment