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

Incorrect WEEK_OF_YEAR for Gregorian Calendar

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2
    • 1.1.6_007
    • 1.1.8, 1.2.0
    • core-libs
    • 007
    • generic
    • generic

    Backports

      Description

        The date is initially set to 31 Dec 2000. The year is then rolled to 2001. The WEEK_OF_YEAR should then be 53 (at least according to the behaviour of 1.1.7). For 1.1.8, WEEK_OF_YEAR=1.

        import java.util.*;
        import java.text.*;

        public class RollYear {

            RollYear() {
                GregorianCalendar cal = new GregorianCalendar();
                cal.setLenient(true);
                cal.setFirstDayOfWeek(2); // Monday
                cal.setMinimalDaysInFirstWeek(4);
                cal.set(2000, 11, 31);
                System.out.print("Initial date : ");
                displayDate(cal);
                cal.roll(cal.YEAR, true); // roll up year by 1
                System.out.print("Rolled to : ");
                displayDate(cal);
                // WEEK_OF_YEAR should now be 53
                int woy = cal.get(cal.WEEK_OF_YEAR);
                if (woy != 53) {
                    throw new RuntimeException("Test Failed: WEEK_OF_YEAR should now be
         53, not " + woy);
                }
                System.out.print("Test Passed");
            }

            void displayDate(GregorianCalendar gc) {
                SimpleDateFormat sdf = new SimpleDateFormat();
                sdf.applyPattern("dd MMM yyyy");
                Date displayDate = gc.getTime();
                System.out.println(sdf.format(displayDate));
            }

            public static void main(String args[]) {
                new RollYear();
            }

        }

        stuart.lawrence@eng 1998-12-15

        There is also a problem when the initial date is 01 Jan 1999 (replace above cal.set(2000, 11, 31) with cal.set(1999, 0, 1)). In this case, after the roll, WEEK_OF_YEAR=0 for 1.1.7 and WEEK_OF_YEAR=53 for 1.1.8 (build C).

        stuart.lawrence@eng 1998-12-16

        Attachments

          Issue Links

            Activity

              People

                aliusunw Alan Liu (Inactive)
                slawson Stuart Lawson
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: