I have a list of dates that i want to ignore :
private val excludeDates = List(
new DateTime("2015-07-17"),
new DateTime("2015-07-20"),
new DateTime("2015-07-23")
)
But i always need to display four dates excluding my black Dates list and the weekends. So far with the following code, my counter is increased when i hit an ignored date and it make sens. So how i can jump to the next date until i hit 4 dates not in my black list and my Weekends ? Maybe with a while, but i dont know how to add it in my scala code :
1 to 4 map { endDate.minusDays(_)} diff excludeDates filter {
_.getDayOfWeek() match {
case DateTimeConstants.SUNDAY | DateTimeConstants.SATURDAY => false
case _ => true
}
}
You could use a Stream
:
val blacklist = excludeDates.toSet
Stream.from(1)
.map(endDate.minusDays(_))
.filter(dt => ! blacklist.contains(dt))
.take(4)
.toList
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With