Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4125881

isLeapYear incorrect for BC years

XMLWordPrintable

    • 1.2beta4
    • x86
    • windows_95
    • Not verified



      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)
      ======================================================================

            aliusunw Alan Liu (Inactive)
            elarsen Erik Larsen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: