If you consider that week will start from Jan 01
of every year & week start is SUNDAY
then there will be 53 weeks in 2019.
Following above Jan 29,30,31 2019
will be into Week-53 of 2019
.
As given in documentation of IsoFields for WEEK_OF_WEEK_BASED_YEAR
that all three fields are validated against their range of valid values. The week-of-week-based-year field is validated from 1 to 52 or 53 depending on the week-based-year.
So I'm assuming that following code should give the output as: WEEK_OF_WEEK_BASED_YEAR
53 & WEEK_BASED_YEAR
2019.
But it's giving output as: 1 & 2020
import java.time.LocalDate;
import java.time.chrono.IsoChronology;
import java.time.format.DateTimeFormatter;
import java.time.format.ResolverStyle;
import java.time.temporal.IsoFields;
public class WeekStartDemo {
public static void main(String args[]) {
DateTimeFormatter DATE_FORMATTER = DateTimeFormatter
.ofPattern("uuuu-MM-dd")
.withChronology(IsoChronology.INSTANCE)
.withResolverStyle(ResolverStyle.STRICT);
LocalDate updatedDate = LocalDate.parse("2019-12-30", DATE_FORMATTER);
System.out.println(updatedDate.toString());
System.out.println(updatedDate.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR));
System.out.println(updatedDate.get(IsoFields.WEEK_BASED_YEAR));
}
}
If I pass the date as 2019-12-28
then it's returning WEEK_OF_WEEK_BASED_YEAR
52 & WEEK_BASED_YEAR
2019. But doesn't work for last week of 2019 (which is 53rd week)
Let me know what I'm missing in above code.