Created
August 2, 2011 00:40
-
-
Save carlohamalainen/1119348 to your computer and use it in GitHub Desktop.
weekdays in a range
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
(ns date-example | |
(:import java.util.Date) | |
(:import java.text.DateFormat)) | |
(def df (DateFormat/getDateInstance)) | |
; Simon's bit | |
(defn weekdays-in-range [start-date end-date] | |
(let [one-day (* 1000 60 60 24) ; millisecs | |
days (map #(new Date %) (range (.getTime start-date) | |
(+ (* one-day 0.5) (.getTime end-date)) | |
one-day))] | |
(filter #(some #{(.getDay %)} [1 2 3 4 5]) days))) | |
(doseq [day (weekdays-in-range (.parse df "1/1/2011") (.parse df "1/8/2011"))] | |
(println day)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment