spkenny

Date Stream

Jun 28th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. import java.time.DayOfWeek;
  2. import java.time.LocalDate;
  3. import java.util.stream.Stream;
  4.  
  5. public class DateStreamTest {
  6.  
  7.     public static void main(String[] args) {
  8.    
  9.         LocalDate localDate = Stream.iterate(getNextDate(LocalDate.of(2017, 7, 1)), t -> getNextDate(t)).limit(4).reduce((a,b) -> b ).orElse(LocalDate.now());
  10.        
  11.         System.out.println(localDate);
  12.  
  13.     }
  14.    
  15.     public static LocalDate getNextDate(LocalDate date) {
  16.         LocalDate returnValue = LocalDate.from(date);
  17.         while (returnValue.plusDays(1).getDayOfWeek() == DayOfWeek.SATURDAY || returnValue.plusDays(1).getDayOfWeek() == DayOfWeek.SUNDAY) {
  18.             returnValue = returnValue.plusDays(1);
  19.         }
  20.        
  21.         return returnValue.plusDays(1);
  22.        
  23.     }
  24.  
  25. }
Add Comment
Please, Sign In to add comment