Details
-
Bug
-
Resolution: Fixed
-
P3
-
7
-
b112
-
generic
-
generic
Description
FULL PRODUCT VERSION :
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b52)
Java HotSpot(TM) Client VM (build 15.0-b03, mixed mode, sharing)
but also happens for latest 1.6
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600] (but happens for all versions)
A DESCRIPTION OF THE PROBLEM :
I've read previous bug reports and it seems like the complication is caused by roll() not changing lower valued fields, but I think it is impossible to justify the current behaviour. If you roll 1 Jan 2010 by 1 WEEK_OF_YEAR you get the WEEK_OF_YEAR moving from 53 to 4 (which isn't a move of 1 by any definition) and the date is 29 January 2010.
I guess Sun wish they'd never written the Spec of roll() as it stands, but I think the current behaviour cannot be justified as meeting the spec.
Test code below.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Test code below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I'd expect 8th January 2010, or if it is assuming this is the 53rd week of 2009, then a day in the first week of 2009.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.*;
public static void main(String [] args) {
Calendar calendar = new GregorianCalendar();
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.MONTH, Calendar.JANUARY);
calendar.set(Calendar.YEAR, 2010);
int week = calendar.get(Calendar.WEEK_OF_YEAR);
System.out.println("week = " + week);
calendar.roll(Calendar.WEEK_OF_YEAR, 1);
int week2 = calendar.get(Calendar.WEEK_OF_YEAR);
System.out.println("week2 = " + week2);
System.out.println("day = " + calendar.get(Calendar.DAY_OF_MONTH));
System.out.println("month = " + calendar.get(Calendar.MONTH));
System.out.println("year = " + calendar.get(Calendar.YEAR));
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Haven't found one yet, but add would probably work.
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b52)
Java HotSpot(TM) Client VM (build 15.0-b03, mixed mode, sharing)
but also happens for latest 1.6
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600] (but happens for all versions)
A DESCRIPTION OF THE PROBLEM :
I've read previous bug reports and it seems like the complication is caused by roll() not changing lower valued fields, but I think it is impossible to justify the current behaviour. If you roll 1 Jan 2010 by 1 WEEK_OF_YEAR you get the WEEK_OF_YEAR moving from 53 to 4 (which isn't a move of 1 by any definition) and the date is 29 January 2010.
I guess Sun wish they'd never written the Spec of roll() as it stands, but I think the current behaviour cannot be justified as meeting the spec.
Test code below.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Test code below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I'd expect 8th January 2010, or if it is assuming this is the 53rd week of 2009, then a day in the first week of 2009.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.*;
public static void main(String [] args) {
Calendar calendar = new GregorianCalendar();
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.MONTH, Calendar.JANUARY);
calendar.set(Calendar.YEAR, 2010);
int week = calendar.get(Calendar.WEEK_OF_YEAR);
System.out.println("week = " + week);
calendar.roll(Calendar.WEEK_OF_YEAR, 1);
int week2 = calendar.get(Calendar.WEEK_OF_YEAR);
System.out.println("week2 = " + week2);
System.out.println("day = " + calendar.get(Calendar.DAY_OF_MONTH));
System.out.println("month = " + calendar.get(Calendar.MONTH));
System.out.println("year = " + calendar.get(Calendar.YEAR));
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Haven't found one yet, but add would probably work.
Attachments
Issue Links
- relates to
-
JDK-4267450 (cal) API: Need public API to calculate, format and parse "year of week"
-
- Closed
-