Skip to content

Instantly share code, notes, and snippets.

@momania
Created January 14, 2020 17:15
Show Gist options
  • Save momania/4bb1c69ec77c0c2c98d72c88c17900af to your computer and use it in GitHub Desktop.
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
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