I am using Joda time api in a Spring 3.0 project for to calculate dates. Now I have a start and end date and I want to get everyday exept weekend or Saturday or Sunday betwe
Neatly using Java 8 Streams:
public LocalDate[] filterWeekdaysForRange(final LocalDate start,final LocalDate end) {
return Stream.iterate(start, date -> date.plusDays(1))
.limit(ChronoUnit.DAYS.between(start, end)+1)
.filter(d->d.getDayOfWeek() != SATURDAY)
.filter(d->d.getDayOfWeek() != SUNDAY)
.toArray(LocalDate[]::new);
}
This is an adaption of a solution provided here: https://stackoverflow.com/a/38220748/744133