Skip to content

Instantly share code, notes, and snippets.

@alandipert
Last active January 6, 2024 07:22
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 alandipert/aa148ac55d219727d694 to your computer and use it in GitHub Desktop.
Save alandipert/aa148ac55d219727d694 to your computer and use it in GitHub Desktop.
Boot script to print the days in some interval to standard out
#!/usr/bin/env boot
(set-env! :dependencies '[[clj-time "0.11.0"]])
(require '[clj-time.core :as t]
'[clj-time.format :as f]
'[boot.cli :refer [defclifn]])
(defn day-range
"Sequence of days from start-day (inclusive) to end-day (exclusive)"
[start-day end-day]
(->> start-day
(iterate #(t/plus % (t/days 1)))
(take-while #(t/before? % end-day))))
(def +default-output-format+ "yyyy-MM-dd")
(defclifn -main
"Prints the days in some interval to standard out."
[s start-day DAY str "Start date (inclusive) in yyyy-MM-dd format."
e end-day DAY str "End date (exclusive) in yyyy-MM-dd format."
f output-format FORMAT str "Optional output format, e.g. \"yyyyMMdd\""]
(if (or start-day end-day)
(let [start (if start-day (f/parse start-day) (t/now))
end (if end-day (f/parse end-day) (t/now))]
(doseq [day (day-range start end)]
(-> (or output-format +default-output-format+)
f/formatter
(f/unparse day)
println)))
(binding [*out* *err*]
(println "One or both of start-day and end-day required.")
(System/exit 1))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment