Skip to content

Instantly share code, notes, and snippets.

@aredington
Created August 23, 2013 15:20
Show Gist options
  • Save aredington/6320532 to your computer and use it in GitHub Desktop.
Save aredington/6320532 to your computer and use it in GitHub Desktop.
Demonstration of using monotony with new period-name fn
(require '[monotony.core :as m])
(def config (m/local-config))
(defn weekday-hours
[conf day]
(let [hours (m/bounded-cycles-in conf day :hour)]
[(nth hours 0) (nth hours 18)]))
(defn weekend-hours
[conf day]
(nth (m/bounded-cycles-in conf day :hour) 15))
(def weeks-out (m/periods config :week (m/next-boundary config :week)))
(def week-days (mapcat #(filter (comp
#{:monday :tuesday :wednesday :thursday :friday}
(partial m/period-name config))
(m/bounded-cycles-in config % :day)) weeks-out))
(def weekend-days (mapcat #(filter (comp #{:saturday :sunday}
(partial m/period-name config))
(m/bounded-cycles-in config % :day)) weeks-out))
(def weekday-schedule (mapcat (partial weekday-hours config) week-days))
(def weekend-schedule (map (partial weekend-hours config) weekend-days))
(def schedule (m/combine weekday-schedule weekend-schedule))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment