Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala : exclude some Dates

Tags:

date

scala

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
              }
            }
like image 661
user708683 Avatar asked Feb 07 '23 23:02

user708683


1 Answers

You could use a Stream :

val blacklist = excludeDates.toSet

Stream.from(1)
      .map(endDate.minusDays(_))
      .filter(dt => ! blacklist.contains(dt))
      .take(4)
      .toList
like image 71
Peter Neyens Avatar answered Feb 11 '23 18:02

Peter Neyens