Skip to content

Instantly share code, notes, and snippets.

Created January 9, 2013 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4497167 to your computer and use it in GitHub Desktop.
Save anonymous/4497167 to your computer and use it in GitHub Desktop.
(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