-
Bug
-
Resolution: Won't Fix
-
P3
-
None
-
1.4.0
-
generic
-
generic
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
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
- relates to
-
JDK-4103271 Calendar Week Nos. 0, 54 invalid
- Closed
-
JDK-4267450 (cal) API: Need public API to calculate, format and parse "year of week"
- Closed