Skip to content

Instantly share code, notes, and snippets.

@siosio
Last active March 1, 2017 07:04
Show Gist options
  • Save siosio/8bbc499c45262d9ba27ef48f9eca2026 to your computer and use it in GitHub Desktop.
Save siosio/8bbc499c45262d9ba27ef48f9eca2026 to your computer and use it in GitHub Desktop.
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.Arrays;
import java.util.stream.IntStream;
public class PremiumFriday {
public static void main(String[] args) {
final LocalDate startDate = LocalDate.of(2017, Month.FEBRUARY, 1);
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd(E)");
IntStream.rangeClosed(2017, 2019)
.boxed()
.flatMap(year -> Arrays.stream(Month.values())
.map(month -> YearMonth.of(year, month).atDay(1)))
.filter(ymd -> !ymd.isBefore(startDate))
.map(ymd -> ymd.with(TemporalAdjusters.lastInMonth(DayOfWeek.FRIDAY)))
.map(formatter::format)
.forEach(System.out::println);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment