As the title states, creating a java.util.GregorianCalendar object, let's say calendar, and running
calendar.getMaximum(Calendar.DAY_OF_WEEK_IN_MONTH)
it returns 6! To the best of my knowledge, this should be 5, since
calendar.getMaximum(Calendar.DAY_OF_MONTH)
equals 31 and 31 / 7 == 4 with a remainder, i.e. there are at most 5 weeks and thus a day can occur at most 5 times in a month.
Am I missing something here?
The javadoc states:
For example, if a month has 31 days, DAY_OF_WEEK_IN_MONTH -1 will overlap DAY_OF_WEEK_IN_MONTH 5 and the end of 4.
This admits, that the maximum value can be 5. In order to have a reason for value six, there would have to be a month with 36 days, which shouldn't happen even with date/time corrections. At least I haven't found anything like that checking information about Gregorian calendar.
So yes, the maximum value should be 5.
Edit: I've also checked the source of the reference implementation and there is no reason for value 6.
You're right, it makes no sense. For DAY_OF_WEEK_IN_MONTH
to be 6
, there would have to be a month with 6 Mondays in it (for example).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With