Hi all,
These days I'm struggling on fixing bugs of GregorainCalendar. I found
strange behavior of RI.
Date date = new Date(Date.parse("Feb 28 00:00:01 GMT 2000"));
GregorianCalendar gc = new GregorianCalendar();
gc.setGregorianChange(date);
gc.setTimeInMillis(Date.parse("Dec 30 00:00:01 GMT 2000"));
System.out.println(gc.get(Calendar.DAY_OF_YEAR));
System.out.println(gc.get(Calendar.DAY_OF_MONTH));
System.out.println(gc.get(Calendar.MONTH));
System.out.println(gc.get(Calendar.YEAR));
System.out.println(gc.get(Calendar.WEEK_OF_YEAR));
System.out.println(gc.getActualMaximum(Calendar.DAY_OF_YEAR));
System.out.println(gc.getActualMaximum(Calendar.WEEK_OF_YEAR));
System.out.println(gc.getLeastMaximum(Calendar.WEEK_OF_YEAR));
RI's output:
352
30
11
2000
51
353
50
50
According to spec, getActualMaximum should return the possiblely
maximun value of the given field. In testcase below, the actual
maximum DAY_OF_YEAR is 353 whereas the the actual maximum WEEK_OF_YEAR
is 50. It is impossible that a year with 353 days contains only 50
weeks.(the FirstDayOfWeek is Sunday and the MinimalDaysInFirstWeek is
1).
What is the more unbelievable is that the
gc.get(Calendar.WEEK_OF_YEAR) returns 51 whereas
gc.getActualMaximum(Calendar.WEEK_OF_YEAR) returns 50. That is the
"Dec 30" is the 51st week of 2000, however, the 2000 contains 50 weeks
at most?
I'm confused, do you have any concern?
--
Tony Wu
China Software Development Lab, IBM