Created
August 19, 2019 23:22
-
-
Save WarFox/adc0946ef9c0717f076f1e8b32555938 to your computer and use it in GitHub Desktop.
Generate infinite date sequences
This file contains hidden or 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
(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