-
Type:
Bug
-
Resolution: Not an Issue
-
Priority:
P4
-
None
-
Affects Version/s: 11, 13, 14
-
Component/s: core-libs
-
x86_64
-
windows_10
ADDITIONAL SYSTEM INFORMATION :
Windows 10, Java 64
the issue is reproducible on Java 7_u25 and java 8_221
A DESCRIPTION OF THE PROBLEM :
If you have a Calendar set to a specific timezone (e.g. "Europe/Budapest"), and you change its MILLISECOND field, the hour field will be incorrectly changed as well.
Work-around: performing a get on the HOUR field, before modifying the MILLISECOND filed will prevent the bug.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
TimeZone tz = TimeZone.getTimeZone("Europe/Budapest");
Calendar calendar = Calendar.getInstance();
// Work-around: uncomment this line to prevent the java Calendar bug
// System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
calendar.set(Calendar.MILLISECOND, 0);
System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Setting the MILLISECOND field won't change the HOUR field
ACTUAL -
Setting the MILLISECOND field changes the HOUR field
---------- BEGIN SOURCE ----------
import java.util.Calendar;
import java.util.TimeZone;
public class TestCalendar {
/**
* @param args
*/
public static void main(String[] args) {
TimeZone tz = TimeZone.getTimeZone("Europe/Budapest");
Calendar calendar = Calendar.getInstance();
// Work-around: uncomment this line to prevent the java Calendar bug
// System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
calendar.set(Calendar.MILLISECOND, 0);
System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
See source code commented out line
FREQUENCY : always
Windows 10, Java 64
the issue is reproducible on Java 7_u25 and java 8_221
A DESCRIPTION OF THE PROBLEM :
If you have a Calendar set to a specific timezone (e.g. "Europe/Budapest"), and you change its MILLISECOND field, the hour field will be incorrectly changed as well.
Work-around: performing a get on the HOUR field, before modifying the MILLISECOND filed will prevent the bug.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
TimeZone tz = TimeZone.getTimeZone("Europe/Budapest");
Calendar calendar = Calendar.getInstance();
// Work-around: uncomment this line to prevent the java Calendar bug
// System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
calendar.set(Calendar.MILLISECOND, 0);
System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Setting the MILLISECOND field won't change the HOUR field
ACTUAL -
Setting the MILLISECOND field changes the HOUR field
---------- BEGIN SOURCE ----------
import java.util.Calendar;
import java.util.TimeZone;
public class TestCalendar {
/**
* @param args
*/
public static void main(String[] args) {
TimeZone tz = TimeZone.getTimeZone("Europe/Budapest");
Calendar calendar = Calendar.getInstance();
// Work-around: uncomment this line to prevent the java Calendar bug
// System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
calendar.set(Calendar.MILLISECOND, 0);
System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
See source code commented out line
FREQUENCY : always
- relates to
-
JDK-4177484 Calendar.setTimeZone() doesn't update all fields
-
- Resolved
-