Name: el35337 Date: 04/04/98
Because there is no year 0, BC leap years fall on years 1 BC, 5 BC, 9 BC,
etc. isLeapYear() puts them on 4, 8, 12, etc. BC. The internal routine used
to convert between time and year-month-day, however, handles the leap year
correctly. Thus, you can see the discrepancy in the following code:
public static void main(String args[]) {
GregorianCalendar gc = new GregorianCalendar (4, Calendar.FEBRUARY, 28);
GregorianCalendar g2 = new GregorianCalendar ();
DateFormat df = DateFormat.getDateInstance(DateFormat.FULL);
gc.set (Calendar.ERA, GregorianCalendar.BC);
// 4 BCE should not be a leap year
System.out.println ("Days in 4 BCE: " + gc.getActualMaximum (Calendar.DAY_OF_YEAR));
System.out.println (df.format (gc.getTime()));
gc.add (Calendar.DATE, 1);
System.out.println (df.format (gc.getTime()));
gc.add (Calendar.YEAR, -1);
// 5 BCE *should* be a leap year
System.out.println ("Days in year 5 BCE: " + gc.getActualMaximum (Calendar.DAY_OF_YEAR));
System.out.println (df.format (gc.getTime()));
gc.add (Calendar.DATE, -1);
System.out.println (df.format (gc.getTime()));
}
This code incidentally demonstrates that an era is missing from the FULL date format (at
least in the US locale, which is my default). While perhaps not a bug, it is no very
desirable feature either.
(Review ID: 27804)
======================================================================
- relates to
-
JDK-4281931 API: GregorianCalendar.isLeapYear() returns a wrong value on BC 1 and AD 4
- Closed