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

(cal) API: WEEK_OF_YEAR numbering doesn't specify a unique date

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P3 P3
    • None
    • 1.4.0
    • core-libs

      The WEEK_OF_YEAR numbering in GregorianCalendar assumes the week-based year numbering. Therefore, the combination of year (Gregorian), week of year and day of week doesn't specify a unique date. Also, setting WEEK_OF_YEAR value to the same one may change the date.

      The following is a program to reproduce the problem.

      --
      import java.util.*;

      public class WeekNumbering {

          static GregorianCalendar gcal = new GregorianCalendar();

          public static void main(String[] args) {
              printDate(2004, Calendar.JANUARY, 1);
              printDate(2004, Calendar.DECEMBER, 30);

              gcal.set(gcal.WEEK_OF_YEAR, gcal.get(gcal.WEEK_OF_YEAR));
              System.out.println(gcal.getTime() + ": week# " +
                              gcal.get(gcal.WEEK_OF_YEAR));
          }

          static void printDate(int year, int month, int dom) {
              gcal.clear();
              gcal.set(year, month, dom);
              System.out.println(gcal.getTime() + ": week# " +
                              gcal.get(gcal.WEEK_OF_YEAR));
          }
      }
      --
      The output in en_US locale:

      Thu Jan 01 00:00:00 PST 2004: week# 1
      Thu Dec 30 00:00:00 PST 2004: week# 1
      Thu Jan 01 00:00:00 PST 2004: week# 1


      ###@###.### 2002-08-14

            okutsu Masayoshi Okutsu
            okutsu Masayoshi Okutsu
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: