A Scala library for calculating all dates between two given dates.
To use the library, import the following:
import zycrophat.datesbetween.DatesBetween._A Seq of dates can be calculated as followed:
val start = LocalDate.of(2020, 3, 1)
val end = LocalDate.of(2020, 3, 6)
val theDatesBetween = datesBetween(start, end) // will include 2020-03-01, ... , 2020-03-06Using inclusive (wihch is the default) and exclusive the upper and lower bounds can be adjusted:
val start = LocalDate.of(2020, 3, 1)
val end = LocalDate.of(2020, 3, 6)
val theDatesBetween = datesBetween(start, end.exclusive) // will include 2020-03-01, ... , 2020-03-05You can also use LocalDateTime instead of LocalDate:
val start = LocalDate.of(2020, 3, 1).atStartOfDay()
val end = LocalDate.of(2020, 3, 6).atTime(13, 37)
val theDatesBetween = datesBetween(start.exclusive, end.exclusive) // will include 2020-03-02, ... , 2020-03-05Or your can use a mixture of different types:
val start = LocalDate.of(2020, 3, 1)
val end = LocalDate.of(2020, 3, 6).atTime(13, 37)
val theDatesBetween = datesBetween(start.exclusive, end.exclusive) // will include 2020-03-02, ... , 2020-03-05For other types you must provide an implicit conversion function, e.g.:
val start = ZonedDateTime.parse("2020-03-01T10:15:30+01:00")
val end = ZonedDateTime.parse("2020-03-06T13:37:42+02:00")
implicit val zonedDateTimeToLocalDate: ZonedDateTime => LocalDate = (zdt: ZonedDateTime) => zdt.toLocalDate
val theDatesBetween = datesBetween(start.exclusive, end) // will include 2020-03-02, ... , 2020-03-06You can also the and method for an even more fluent experience:
val start = LocalDate.of(2020, 3, 1)
val end = LocalDate.of(2020, 3, 6).atTime(13, 37)
val theDatesBetween = datesBetween(start.exclusive and end.exclusive, Period.ofDays(2))- Tested on JDK 11 (but should work on JDK 8)
$ sbt testTo run with coverage report:
$ sbt test coverageReportA scoverage report will be created in the directory target/scala-2.11/scoverage-report.
$ sbt packageMIT License