Created
January 14, 2020 17:15
-
-
Save momania/4bb1c69ec77c0c2c98d72c88c17900af to your computer and use it in GitHub Desktop.
Simple Scala date util to get all week days between two given dates
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
import java.time.{DayOfWeek, LocalDate} | |
object DateUtil { | |
@inline private def isWeekend(d: LocalDate): Boolean = { | |
d.getDayOfWeek == DayOfWeek.SATURDAY || d.getDayOfWeek == DayOfWeek.SUNDAY | |
} | |
def businessDayStream(from: LocalDate, to: LocalDate): Stream[LocalDate] = { | |
Stream.iterate(from)(_.plusDays(1)).filterNot(isWeekend).takeWhile(_.isBefore(to)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment