I would like to convert a YearMonth to a LocalDate with the specified DayOfWeek, e.g. the second Tuesday of February 2019.
The following code throws a DateTimeException:
YearMonth yearMonth = YearMonth.of(2019, Month.FEBRUARY);
TemporalAdjuster secondTuesday = TemporalAdjusters.dayOfWeekInMonth(2, DayOfWeek.TUESDAY);
LocalDate date = LocalDate.from(yearMonth).with(secondTuesday);
In order to make my code work I need to replace the last line with
LocalDate date = yearMonth.atDay(1).with(secondTuesday);
Isn't there a cleaner solution that doesn't require the use of atDay(1)?