Skip to content

Instantly share code, notes, and snippets.

@WarFox
Created August 19, 2019 23: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 WarFox/adc0946ef9c0717f076f1e8b32555938 to your computer and use it in GitHub Desktop.
Save WarFox/adc0946ef9c0717f076f1e8b32555938 to your computer and use it in GitHub Desktop.
Generate infinite date sequences
(ns warfox.date
(:import [java.time LocalDate]
[java.time.temporal ChronoUnit]))
(defn date-seq
"Returns lazy sequence of dates starting from `start`"
[^LocalDate start]
(lazy-seq
(cons start
(date-seq (.plusDays start 1)))))
(defn days-between
"Returns the number of days between `start` and `end`"
[^LocalDate start ^LocalDate end]
(.until start end ChronoUnit/DAYS))
(defn date-sequence
"Returns a dates between `start` and `end` date"
[^LocalDate start ^LocalDate end]
(let [days-between (days-between start end)]
(take days-between (date-seq start))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment