Last active
January 6, 2024 07:22
-
-
Save alandipert/aa148ac55d219727d694 to your computer and use it in GitHub Desktop.
Boot script to print the days in some interval to standard out
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
#!/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