JDK-4252550 : Leap Year problem in java.util.GregorianCalendar's isLeapYear(int) method.
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 1.2.2
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1999-07-08
  • Updated: 1999-07-20
  • Resolved: 1999-07-20
Description

Name: skT88420			Date: 07/08/99


When running the following piece of code I got the
message saying 
1100 is a leap year
1300 is a leap year
1400 is a leap year
1500 is a leap year
According to the rules defined for leap year the above years are 
NOT leap years.
The full leap year rules
The full rules for calculating whether a year is a leap year or not are - 

                        If the number of the year can be divided by 400 without leaving any remainder; it is a leap year

                                                           otherwise

                      If the number of the year can be divided by 100 without leaving any remainder; it is not a leap year

                                                           otherwise

                        If the number of the year can be divided by four without leaving any remainder; it is a leap year

                                                           otherwise

                                                      It is not a leap year

1.Please save the following piece of program in a file called DateTest.java
and compile with Sun JDK1.2 java compiler and execute using the java interpreter.
2.The SOURCE code
import java.util.*;
public class DateTest{
	public static void main(String av[]){
		GregorianCalendar c = new GregorianCalendar();
		String leap = (c.isLeapYear(Integer.parseInt(av[0])))?"":" NOT";
		System.out.println(av[0]+ " is" + leap + " a leap year" );
	}
}
3.The output of the above program
I:\Developers\giri>java DateTest 1100
1100 is a leap year
I:\Developers\giri>java DateTest 1300
1300 is a leap year
I:\Developers\giri>java DateTest 1400
1400 is a leap year
I:\Developers\giri>java DateTest 1500
1500 is a leap year

4.No trace information
5.Output of java -version and java -fullversion
I:\Developers\giri>java -version
java version "1.2"
Classic VM (build JDK-1.2-V, native threads)

I:\Developers\giri>java -fullversion
java full version "JDK-1.2-V"
(Review ID: 85356) 
======================================================================

Comments
WORK AROUND Name: skT88420 Date: 07/08/99 Incorporate the leap year rules in one of the user defined util classes ======================================================================
11-06-2004

EVALUATION The javadoc for GregorianCalendar says: "Before the Gregorian cutover [October 15, 1582], GregorianCalendar implements the Julian calendar. The only difference between the Gregorian and the Julian calendar is the leap year rule. The Julian calendar specifies leap years every four years, whereas the Gregorian calendar omits century years which are not divisible by 400." The described results are therefore correct. norbert.lindenberg@Eng 1999-07-20
20-07-1999