Skip to content

Instantly share code, notes, and snippets.

@craftybones
Created August 30, 2019 02:18
Show Gist options
  • Save craftybones/f0eba869e3bcfdc47d4f6bfe2ebc6b2c to your computer and use it in GitHub Desktop.
Save craftybones/f0eba869e3bcfdc47d4f6bfe2ebc6b2c to your computer and use it in GitHub Desktop.
(defn divisible-by? [x y]
(zero? (rem y x)))
(defn leap? [year]
(condp divisible-by? year
400 true
100 false
4 true
false))
(def days [31 28 31 30 31 30 31 31 30 31 30 31])
(def max-days {false days true (assoc-in days [1] 29)})
(defn max-days-for [year month]
(get-in max-days [(leap? year) (dec month)] -1))
(defn valid-date? [year month day]
(when-let [max-days-for-month (max-days-for year month)]
(<= 1 day max-days-for-month)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment