Skip to content

Instantly share code, notes, and snippets.

@mfikes
Last active August 29, 2015 14:17
Show Gist options
  • Save mfikes/bae5cc6ee6292b19e4c2 to your computer and use it in GitHub Desktop.
Save mfikes/bae5cc6ee6292b19e4c2 to your computer and use it in GitHub Desktop.
Date range
(import '[goog.date Date Interval])
; This one goes from today up to but not including the end-date
(defn date-range-from-today [end-date]
(let [day-range (Interval. 0 0 1)]
(loop [i (Date.) v (transient [])]
(if (not (.equals end-date i))
(do
(let [x (doto (.clone i) (.add day-range))]
(recur x (conj! v x))))
(persistent! v)))))
; This one goes from tomorrow up to and including the end-date
(defn date-range-from-today' [end-date]
(let [day-range (Interval. 0 0 1)]
(loop [i (Date.) v (transient [])]
(if (not (.equals end-date i))
(do
(let [x (doto (.clone i) (.add day-range))]
(recur x (conj! v i))))
(persistent! v)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment