-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
6u45
-
linux_ubuntu
FULL PRODUCT VERSION :
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) Server VM (build 20.45-b01, mixed mode
ADDITIONAL OS VERSION INFORMATION :
Linux 3.2.0-53-generic-pae #81-Ubuntu SMP Thu Aug 22 21:23:47 UTC 2013 i686 i686 i386 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
When a "Calendar.set(DAY_OF_WEEK, n)" occurs right after a "Calendar.set(YEAR, MONTH, DATE)", the latter does not seem to be taken into account.
The "Calendar.set(DAY_OF_WEEK)" seems to be applied to a date which week number of the month is the same as the execution date.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
<code>
import java.util.*;
public class CalendarTest {
public static void main(String[] args) throws java.lang.Exception {
System.out.println("java.version = " + System.getProperty("java.version"));
System.out.println("java.vendor = " + System.getProperty("java.vendor"));
Calendar cal = Calendar.getInstance();
cal.setFirstDayOfWeek(Calendar.MONDAY);
cal.setMinimalDaysInFirstWeek(4);
cal.set(2013, Calendar.AUGUST, 20); // TUESDAY
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
// Execution date: December 12th, 2013 (2nd week of December 2013)
System.out.println(cal.getTime());
// Expected: August 19th, 2013
// Obtained: August 5th, 2013 (Monday of the 2nd week of August 2013)
}
}
</code>
Tested with Java 6:
<output>
java.version = 1.6.0_45
java.vendor = Sun Microsystems Inc.
Mon Aug 05 11:45:42 CEST 2013
</output>
Tested with Java 7:
<output>
java.version = 1.7.0_45
java.vendor = Oracle Corporation
Mon Aug 05 12:02:05 CEST 2013
</output>
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Calling "Calendar.getTime()" after "Calendar.set(YEAR, MONTH, DATE".
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) Server VM (build 20.45-b01, mixed mode
ADDITIONAL OS VERSION INFORMATION :
Linux 3.2.0-53-generic-pae #81-Ubuntu SMP Thu Aug 22 21:23:47 UTC 2013 i686 i686 i386 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
When a "Calendar.set(DAY_OF_WEEK, n)" occurs right after a "Calendar.set(YEAR, MONTH, DATE)", the latter does not seem to be taken into account.
The "Calendar.set(DAY_OF_WEEK)" seems to be applied to a date which week number of the month is the same as the execution date.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
<code>
import java.util.*;
public class CalendarTest {
public static void main(String[] args) throws java.lang.Exception {
System.out.println("java.version = " + System.getProperty("java.version"));
System.out.println("java.vendor = " + System.getProperty("java.vendor"));
Calendar cal = Calendar.getInstance();
cal.setFirstDayOfWeek(Calendar.MONDAY);
cal.setMinimalDaysInFirstWeek(4);
cal.set(2013, Calendar.AUGUST, 20); // TUESDAY
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
// Execution date: December 12th, 2013 (2nd week of December 2013)
System.out.println(cal.getTime());
// Expected: August 19th, 2013
// Obtained: August 5th, 2013 (Monday of the 2nd week of August 2013)
}
}
</code>
Tested with Java 6:
<output>
java.version = 1.6.0_45
java.vendor = Sun Microsystems Inc.
Mon Aug 05 11:45:42 CEST 2013
</output>
Tested with Java 7:
<output>
java.version = 1.7.0_45
java.vendor = Oracle Corporation
Mon Aug 05 12:02:05 CEST 2013
</output>
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Calling "Calendar.getTime()" after "Calendar.set(YEAR, MONTH, DATE".
- duplicates
-
JDK-8366740 Wrong GregorianCalendar value changing the day of the week
-
- Closed
-