Skip to content

Instantly share code, notes, and snippets.

@sritchie
Created February 16, 2011 03:56
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 sritchie/542ce3e9533201c3b457 to your computer and use it in GitHub Desktop.
Save sritchie/542ce3e9533201c3b457 to your computer and use it in GitHub Desktop.
(defn delta-periods
[start end unit span]
(let [[years units] (map #(delta % start end) [year unit])
top (per-year unit span)]
(+ (* top years)
(int (/ units span)))))
(defn sixteens
[start end]
(delta-periods start end day 16))
(defn eights
[start end]
(delta-periods start end day 8))
(defn months
[start end]
(delta-periods start end month 1))
;; or this:
(defn delta-periods
[unit span]
(fn [start end]
(let [[years units] (map #(delta % start end) [year unit])
top (per-year unit span)]
(+ (* top years)
(int (/ units span))))))
(def sixteens (delta-periods day 16))
(def eights (delta-periods day 8))
(def months (delta-periods month 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment