United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4731296 : (cal) API: WEEK_OF_YEAR numbering doesn't specify a unique date

Details
Type:
Bug
Submit Date:
2002-08-14
Status:
Closed
Updated Date:
2005-03-30
Project Name:
JDK
Resolved Date:
2002-08-14
Component:
core-libs
OS:
generic
Sub-Component:
java.util:i18n
CPU:
generic
Priority:
P3
Resolution:
Won't Fix
Affected Versions:
1.4.0
Fixed Versions:

Related Reports
Relates:
Relates:

Sub Tasks

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
                                     
2002-08-14



Hardware and Software, Engineered to Work Together