JDK-4731296 : (cal) API: WEEK_OF_YEAR numbering doesn't specify a unique date
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Closed
  • Resolution: Won't Fix
  • OS: generic
  • CPU: generic
  • Submitted: 2002-08-14
  • Updated: 2005-03-30
  • Resolved: 2002-08-14
Related Reports
Relates :  
Relates :  
Description
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

Comments
EVALUATION The WEEK_OF_YEAR numbering should have been based on the Gregorian year numbering so that the year, week of year and day of week can specify a unique date. Also, the week-based year and week of year should have been another fields with get/set methods support. It's too late to make changes to GregorianCalendar. ###@###.### 2002-08-14
14-08-2002