Calendar.getActualMaximum (Calendar.WEEK_OF_YEAR) weirdness

Either I do not understand the getActualMaximum(int) method, or the WEEK_OF_YEAR field, or there is a Sun error (or all three) ... can someone explain to me why (at least in the German locale ...) the following code:

  Locale.setDefault( Locale.GERMAN ); Calendar c = Calendar.getInstance(); c.set( Calendar.YEAR, 2010 ); c.set( Calendar.MONTH, 0 ); c.set( Calendar.DAY_OF_MONTH, 1 ); System.out.println("max: "+c.getActualMaximum( Calendar.WEEK_OF_YEAR )); System.out.println("actual: "+c.get( Calendar.WEEK_OF_YEAR )); 

outputs the following result:

  max: 52 actual: 53 

Here's the Javadoc getActualMaximum(int) :

Returns the maximum value that the specified calendar field can have, given the time value of this Calendar. For example, the actual maximum value of the MONTH field is 12 in some years and 13 in other years in the Jewish calendar system.


Edit

The plot is thickening. In the English locale ( -Duser.language=en -Duser.country=us ) the output is:

  max: 52 actual: 1 

Does it seem to indicate that this is a Sun bug for German locales?

+4
source share
2 answers

This information is correct:

 max: 52 actual: 53 

In 2010, no more than 52 weeks. The actual week is 53, since 2009 it is a maximum of 53 weeks, and most weeks begin on Sunday or Monday. Week 1 in most cases is the first week of the year with 4 days in January. Since the week of January 1 has only 2 or 3 days in 2010, the week is considered part of 2009.

Most likely, the English language has different rules for determining week 1, for example, the first week is the week of January 1.

Wikipedia explains this correctly: Wikipedia article of the week

+3
source

The problem is that on January 1, 2010 at week 53 of 2009 (in Germany), but in 2010 only 52 weeks (December 31, 2010 at 52 week). Unfortunately, the Java Calendar object does not have a field for the year to which the week number refers.

+2
source

All Articles