-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
7, 8, 9
-
generic
-
generic
FULL PRODUCT VERSION :
1.7.0_07-B11 32 Bit Windows and 1.8.0_66-B17 32 Bit Windows
ADDITIONAL OS VERSION INFORMATION :
Windows 7, Windows 2008, 64 Bit
A DESCRIPTION OF THE PROBLEM :
Error in calendar. setting MILLISECOND when changing from summer to wintertime makes an error of 3600 seconds
REGRESSION. Last worked in version 8u66
ADDITIONAL REGRESSION INFORMATION:
1.7.0_07-B11 32 Bit Windows and 1.8.0_66-B17 32 Bit Windows
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
* Timezone Berlin (GMT+1) and summer/wintertime
*
* In october at the last weekend the time changes from summer to wintertime
*
* Example:
*
* 25.10.2015 1:59:59 summertime (25 october 2015)
* 25.10.2015 2:00:00 summertime
* 25.10.2015 2:00:01 summertime
* ...
* 25.10.2015 2:59:59 summertime
* 25.10.2015 2:00:00 wintertime
* 25.10.2015 2:00:01 wintertime
* ...
* 25.10.2015 2:59:59 wintertime
* 25.10.2015 3:00:00 wintertime
* 25.10.2015 3:00:01 wintertime
* Error: Setting Milliseconds changes Summer to wintertime --> Error of 3600 seconds !!!
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
correct Setting of the calendar
ERROR MESSAGES/STACK TRACES THAT OCCUR :
no crash
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package emi3000test;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;
public class TestSummerToWinterTimeInGermany {
static Calendar cal;
/*
* Java: 1.7.0_07-B11 32 Bit Windows and 1.8.0_66-B17 32 Bit Windows
* Operating system: Windows 7 professional 64 Bit, Windows 2008
*
* Timezone Berlin (GMT+1) and summer/wintertime
*
* In october at the last weekend the time changes from summer to wintertime
*
* Example:
*
* 25.10.2015 1:59:59 summertime (25 october 2015)
* 25.10.2015 2:00:00 summertime
* 25.10.2015 2:00:01 summertime
* ...
* 25.10.2015 2:59:59 summertime
* 25.10.2015 2:00:00 wintertime
* 25.10.2015 2:00:01 wintertime
* ...
* 25.10.2015 2:59:59 wintertime
* 25.10.2015 3:00:00 wintertime
* 25.10.2015 3:00:01 wintertime
*
* Joerg Acker, company ITBK, 31 October 2015
*/
public static void main(String[] args) {
cal = Calendar.getInstance();
cal.setTimeInMillis(0);
cal.setFirstDayOfWeek(Calendar.MONDAY);
/*
* Error: Setting Milliseconds changes Summer to wintertime --> Error of 3600 seconds !!!
*/
set(2015, 9, 25, 1, 59, 59);
System.out.println(toCalString()); // 25.10.2015 01:59:59.0000 Mitteleuropäische Sommerzeit
set(Calendar.MILLISECOND, 234);
// the last three lines is normally System.currentTimeMillis()
System.out.println(toCalString()); // 25.10.2015 01:59:59.0234 Mitteleuropäische Sommerzeit
add(Calendar.SECOND, 1);
System.out.println(toCalString()); // 25.10.2015 02:00:00.0234 Mitteleuropäische Sommerzeit
set(Calendar.MILLISECOND, 0);
System.out.println(toCalString()); // 25.10.2015 02:00:00.0000 Mitteleuropäische Zeit
/*
* In Summer there is no error
*/
set(2015, 6, 25, 1, 59, 59);
System.out.println(toCalString()); // 25.7.2015 01:59:59.0000 Mitteleuropäische Sommerzeit
set(Calendar.MILLISECOND, 234);
// the last three lines is normally System.currentTimeMillis()
System.out.println(toCalString()); // 25.7.2015 01:59:59.0234 Mitteleuropäische Sommerzeit
add(Calendar.SECOND, 1);
System.out.println(toCalString()); // 25.7.2015 02:00:00.0234 Mitteleuropäische Sommerzeit
set(Calendar.MILLISECOND, 0);
System.out.println(toCalString()); // 25.7.2015 02:00:00.0000 Mitteleuropäische Sommerzeit
/*
* In Winter there is no error
*/
set(2015, 0, 25, 1, 59, 59);
System.out.println(toCalString()); // 25.1.2015 01:59:59.0000 Mitteleuropäische Sommerzeit
set(Calendar.MILLISECOND, 234);
// the last three lines is normally System.currentTimeMillis()
System.out.println(toCalString()); // 25.1.2015 01:59:59.0234 Mitteleuropäische Sommerzeit
add(Calendar.SECOND, 1);
System.out.println(toCalString()); // 25.1.2015 02:00:00.0234 Mitteleuropäische Sommerzeit
set(Calendar.MILLISECOND, 0);
System.out.println(toCalString()); // 25.1.2015 02:00:00.0000 Mitteleuropäische Sommerzeit
/*
* Bugfix set MILLISECOND
*/
set(2015, 9, 25, 1, 59, 59);
System.out.println(toCalString()); // 25.10.2015 01:59:59.0000 Mitteleuropäische Sommerzeit
set(Calendar.MILLISECOND, 234);
// the last three lines is normally System.currentTimeMillis()
System.out.println(toCalString()); // 25.10.2015 01:59:59.0234 Mitteleuropäische Sommerzeit
add(Calendar.SECOND, 1);
System.out.println(toCalString()); // 25.10.2015 02:00:00.0234 Mitteleuropäische Sommerzeit
setBugFix(Calendar.MILLISECOND, 0);
System.out.println(toCalString()); // 25.10.2015 02:00:00.0000 Mitteleuropäische Sommerzeit
}
public static void add(int field, int amount) {
cal.add(field, amount);
}
public static void set(int year, int month, int date, int hrs, int min,
int sec) {
cal.set(year, month, date, hrs, min, sec);
}
public static void set(int field, int amount) {
cal.set(field, amount);
}
public static void setBugFix(int field, int amount) {
if(field == Calendar.MILLISECOND){
long millis = cal.getTimeInMillis() / 1000;
millis *= 1000;
millis += amount;
cal.setTimeInMillis(millis);
}
else{
cal.set(field, amount);
}
}
public static String toCalString() {
SimpleDateFormat s = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss.SSSS zzzz");
return s.format(cal.getTime());
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
see my source code
1.7.0_07-B11 32 Bit Windows and 1.8.0_66-B17 32 Bit Windows
ADDITIONAL OS VERSION INFORMATION :
Windows 7, Windows 2008, 64 Bit
A DESCRIPTION OF THE PROBLEM :
Error in calendar. setting MILLISECOND when changing from summer to wintertime makes an error of 3600 seconds
REGRESSION. Last worked in version 8u66
ADDITIONAL REGRESSION INFORMATION:
1.7.0_07-B11 32 Bit Windows and 1.8.0_66-B17 32 Bit Windows
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
* Timezone Berlin (GMT+1) and summer/wintertime
*
* In october at the last weekend the time changes from summer to wintertime
*
* Example:
*
* 25.10.2015 1:59:59 summertime (25 october 2015)
* 25.10.2015 2:00:00 summertime
* 25.10.2015 2:00:01 summertime
* ...
* 25.10.2015 2:59:59 summertime
* 25.10.2015 2:00:00 wintertime
* 25.10.2015 2:00:01 wintertime
* ...
* 25.10.2015 2:59:59 wintertime
* 25.10.2015 3:00:00 wintertime
* 25.10.2015 3:00:01 wintertime
* Error: Setting Milliseconds changes Summer to wintertime --> Error of 3600 seconds !!!
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
correct Setting of the calendar
ERROR MESSAGES/STACK TRACES THAT OCCUR :
no crash
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package emi3000test;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;
public class TestSummerToWinterTimeInGermany {
static Calendar cal;
/*
* Java: 1.7.0_07-B11 32 Bit Windows and 1.8.0_66-B17 32 Bit Windows
* Operating system: Windows 7 professional 64 Bit, Windows 2008
*
* Timezone Berlin (GMT+1) and summer/wintertime
*
* In october at the last weekend the time changes from summer to wintertime
*
* Example:
*
* 25.10.2015 1:59:59 summertime (25 october 2015)
* 25.10.2015 2:00:00 summertime
* 25.10.2015 2:00:01 summertime
* ...
* 25.10.2015 2:59:59 summertime
* 25.10.2015 2:00:00 wintertime
* 25.10.2015 2:00:01 wintertime
* ...
* 25.10.2015 2:59:59 wintertime
* 25.10.2015 3:00:00 wintertime
* 25.10.2015 3:00:01 wintertime
*
* Joerg Acker, company ITBK, 31 October 2015
*/
public static void main(String[] args) {
cal = Calendar.getInstance();
cal.setTimeInMillis(0);
cal.setFirstDayOfWeek(Calendar.MONDAY);
/*
* Error: Setting Milliseconds changes Summer to wintertime --> Error of 3600 seconds !!!
*/
set(2015, 9, 25, 1, 59, 59);
System.out.println(toCalString()); // 25.10.2015 01:59:59.0000 Mitteleuropäische Sommerzeit
set(Calendar.MILLISECOND, 234);
// the last three lines is normally System.currentTimeMillis()
System.out.println(toCalString()); // 25.10.2015 01:59:59.0234 Mitteleuropäische Sommerzeit
add(Calendar.SECOND, 1);
System.out.println(toCalString()); // 25.10.2015 02:00:00.0234 Mitteleuropäische Sommerzeit
set(Calendar.MILLISECOND, 0);
System.out.println(toCalString()); // 25.10.2015 02:00:00.0000 Mitteleuropäische Zeit
/*
* In Summer there is no error
*/
set(2015, 6, 25, 1, 59, 59);
System.out.println(toCalString()); // 25.7.2015 01:59:59.0000 Mitteleuropäische Sommerzeit
set(Calendar.MILLISECOND, 234);
// the last three lines is normally System.currentTimeMillis()
System.out.println(toCalString()); // 25.7.2015 01:59:59.0234 Mitteleuropäische Sommerzeit
add(Calendar.SECOND, 1);
System.out.println(toCalString()); // 25.7.2015 02:00:00.0234 Mitteleuropäische Sommerzeit
set(Calendar.MILLISECOND, 0);
System.out.println(toCalString()); // 25.7.2015 02:00:00.0000 Mitteleuropäische Sommerzeit
/*
* In Winter there is no error
*/
set(2015, 0, 25, 1, 59, 59);
System.out.println(toCalString()); // 25.1.2015 01:59:59.0000 Mitteleuropäische Sommerzeit
set(Calendar.MILLISECOND, 234);
// the last three lines is normally System.currentTimeMillis()
System.out.println(toCalString()); // 25.1.2015 01:59:59.0234 Mitteleuropäische Sommerzeit
add(Calendar.SECOND, 1);
System.out.println(toCalString()); // 25.1.2015 02:00:00.0234 Mitteleuropäische Sommerzeit
set(Calendar.MILLISECOND, 0);
System.out.println(toCalString()); // 25.1.2015 02:00:00.0000 Mitteleuropäische Sommerzeit
/*
* Bugfix set MILLISECOND
*/
set(2015, 9, 25, 1, 59, 59);
System.out.println(toCalString()); // 25.10.2015 01:59:59.0000 Mitteleuropäische Sommerzeit
set(Calendar.MILLISECOND, 234);
// the last three lines is normally System.currentTimeMillis()
System.out.println(toCalString()); // 25.10.2015 01:59:59.0234 Mitteleuropäische Sommerzeit
add(Calendar.SECOND, 1);
System.out.println(toCalString()); // 25.10.2015 02:00:00.0234 Mitteleuropäische Sommerzeit
setBugFix(Calendar.MILLISECOND, 0);
System.out.println(toCalString()); // 25.10.2015 02:00:00.0000 Mitteleuropäische Sommerzeit
}
public static void add(int field, int amount) {
cal.add(field, amount);
}
public static void set(int year, int month, int date, int hrs, int min,
int sec) {
cal.set(year, month, date, hrs, min, sec);
}
public static void set(int field, int amount) {
cal.set(field, amount);
}
public static void setBugFix(int field, int amount) {
if(field == Calendar.MILLISECOND){
long millis = cal.getTimeInMillis() / 1000;
millis *= 1000;
millis += amount;
cal.setTimeInMillis(millis);
}
else{
cal.set(field, amount);
}
}
public static String toCalString() {
SimpleDateFormat s = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss.SSSS zzzz");
return s.format(cal.getTime());
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
see my source code
- duplicates
-
JDK-8038386 java.util.Calendar: Subtract hour then set minute around DST returns bad result
-
- Closed
-