A Java 8 answer would be the following (if you're only looking for Sundays):
LocalDate closestSunday = LocalDate.now().with(TemporalAdjusters.previousOrSame(DayOfWeek.SUNDAY));
LocalDate firstSunday = closestSunday.minusMonths(3);
List<LocalDate> sundays = new ArrayList<>();
for (; !closestSunday.isBefore(firstSunday); closestSunday = closestSunday.minusWeeks(1)) {
sundays.add(closestSunday);
}
I would use a Stream
approach, but I'd rather wait 8 days until JDK 9 is released so I can use Stream#takeWhile
.
EDIT: If you really want a Stream
approach utilizing JDK 8, then the following is logically equivalent to the code above:
LocalDate closestSunday = LocalDate.now().with(TemporalAdjusters.previousOrSame(DayOfWeek.SUNDAY));
LocalDate secondSunday = closestSunday.minusMonths(3).plusWeeks(1);
List<LocalDate> sundays = new ArrayList<>();
Stream.iterate(closestSunday, date -> date.minusWeeks(1))
.peek(sundays::add)
.allMatch(date -> date.isAfter(secondSunday));