Created
January 9, 2013 21:35
-
-
Save anonymous/4497167 to your computer and use it in GitHub Desktop.
This file contains 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
(require ['clj-time.core :as 'time]) | |
(defn fill-interval [start end minutes] | |
"Returns a sequence of DateTimes n minutes apart between start and end" | |
(let [interval (time/interval start end)] | |
(if (< (time/in-minutes interval) minutes) | |
(list start) | |
(cons start | |
(recur (time/plus start (time/minutes minutes)) | |
end | |
minutes))))) | |
(let | |
[start-date (string-to-real-date "2012-01-09 12:00:00") | |
end-date (string-to-real-date "2012-01-09 12:35:00")] | |
(fill-interval start-date end-date 15)) | |
;;Expected result: One flat sequence: | |
;;(#<DateTime 2012-01-09T12:00:00.000Z> #<DateTime 2012-01-09T12:15:00.000Z> #<DateTime 2012-01-09T12:30:00.000Z>) | |
;;Actual result: Two nested sequences: | |
;;(#<DateTime 2012-01-09T12:00:00.000Z> (#<DateTime 2012-01-09T12:15:00.000Z> #<DateTime 2012-01-09T12:30:00.000Z>)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment