Last active
August 29, 2015 14:17
-
-
Save mfikes/bae5cc6ee6292b19e4c2 to your computer and use it in GitHub Desktop.
Date range
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
| (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