Given:
- A Year: 2019
- A Calender Week Number: 1 (== 1st Week of a year)
- A DayOfWeek: SUNDAY
Needed:
A transformation f of those Infos into a LocalDate Object so that
assertEquals(LocalDate.of(2019,1,6), f(2019,1,SUNDAY))
What I tried
I did not find a way with java.time.* to create a Date from an Info like "The Sunday of the first calender week in 2019". I found that the old java.util.Calendar class had a setWeekDate() function that could be usefull. But the following code caused an Exception:
...
Calendar c = Calendar.getInstance();
c.setWeekDate(2019, 1, Calendar.MONDAY);
c.setTimeZone(TimeZone.getDefault());
return LocalDate.from(c.toInstant());
java.time.DateTimeException: Unable to obtain LocalDate from TemporalAccessor: 2018-01-08T20:03:55.602Z of type java.time.Instant
at java.time.LocalDate.from(LocalDate.java:379)
at ...