Let me quote from the source:
/**
* Field number for <code>get</code> and <code>set</code> indicating the
* week number within the current year. The first week of the year, as
* defined by <code>getFirstDayOfWeek()</code> and
* <code>getMinimalDaysInFirstWeek()</code>, has value 1. Subclasses define
* the value of <code>WEEK_OF_YEAR</code> for days before the first week of
* the year.
*
* @see #getFirstDayOfWeek
* @see #getMinimalDaysInFirstWeek
*/
Let us have a look at this experiment:
public static void main(String[] args) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date procDate = sdf.parse("2016-01-01");
Calendar cal = Calendar.getInstance(Locale.UK);
cal.setFirstDayOfWeek(Calendar.SUNDAY);
cal.setTime(procDate);
System.out.println(cal.get(Calendar.WEEK_OF_YEAR) );
System.out.println(cal.get(Calendar.YEAR) );
cal.add(Calendar.DAY_OF_YEAR, 1);
System.out.println(cal.get(Calendar.WEEK_OF_YEAR) );
System.out.println(cal.get(Calendar.YEAR) );
cal.add(Calendar.DAY_OF_YEAR, 1);
System.out.println(cal.get(Calendar.DAY_OF_YEAR));
System.out.println(cal.get(Calendar.WEEK_OF_YEAR) );
System.out.println(cal.get(Calendar.YEAR) );
procDate = sdf.parse("2016-12-27");
cal.setTime(procDate);
System.out.println(cal.get(Calendar.WEEK_OF_YEAR) );
System.out.println(cal.get(Calendar.YEAR) );
}
52
2016
52
2016
3
1
2016
52
2016
Conclusion:
WEEK_OF_YEAR
is set to 1 on the first day of the full week in year. Before this day, it depends on implementation. In default Java implementation it is 52 by default. You can set cal.setMinimalDaysInFirstWeek(1);
and then it should fix your case.
Why? Ask guys from Sun.