FULL PRODUCT VERSION :
java version "1.4.2_12"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.
Java HotSpot(TM) Client VM (build 1.4.2_12-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Parsing of date strings with timezone ids that indicate a timezone in day light saving time in it is broken. For example "2006-12-20 17:06:07 MDT" is parsed like it was "2006-12-20 17:06:07 MST". The MDT has another offset to GMT than MST, this should taken into account.
Might be related to http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6466476 . However, this bug is submitted because of the parsing of the timezone ids. Such an id such just indicate an offset to GMT while parsing. (I'm aware that multiple timezones can have the same ID..)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached program. SimpleDateFormat is not able to parse strings like "2006-12-20 17:06:07 MDT" correctly
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
no errors should be reported
(Just like when the program is run with java version
java version "1.4.2_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_08-b03)
Java HotSpot(TM) Client VM (build 1.4.2_08-b03, mixed mode)
)
ACTUAL -
Unable to parse <2006-12-20 17:06:07 MDT> expected 2006-12-20 23:06:07 GMT was 2
006-12-21 00:06:07 GMT
Unable to parse <2006-12-20 17:06:07 EDT> expected 2006-12-20 21:06:07 GMT was 2
006-12-20 22:06:07 GMT
Unable to parse <2006-06-20 17:06:07 MDT> expected 2006-06-20 23:06:07 GMT was 2
006-06-21 00:06:07 GMT
Unable to parse <2006-06-20 17:06:07 EDT> expected 2006-06-20 21:06:07 GMT was 2
006-06-20 22:06:07 GMT
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
Run the following java program
import java.text.*;
import java.util.*;
public class DateParse
{
public static void main(String[] args)
{
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
String input[] = {
"2006-12-20 17:06:07 GMT",
"2006-12-20 17:06:07 PST",
"2006-12-20 17:06:07 PDT",
"2006-12-20 17:06:07 MST",
"2006-12-20 17:06:07 MDT",
"2006-12-20 17:06:07 CST",
"2006-12-20 17:06:07 CDT",
"2006-12-20 17:06:07 EST",
"2006-12-20 17:06:07 EDT",
"2006-06-20 17:06:07 GMT",
"2006-06-20 17:06:07 PST",
"2006-06-20 17:06:07 PDT",
"2006-06-20 17:06:07 MST",
"2006-06-20 17:06:07 MDT",
"2006-06-20 17:06:07 CST",
"2006-06-20 17:06:07 CDT",
"2006-06-20 17:06:07 EST",
"2006-06-20 17:06:07 EDT",
};
String[] expected = {
"2006-12-20 17:06:07 GMT",
"2006-12-21 01:06:07 GMT",
"2006-12-21 00:06:07 GMT",
"2006-12-21 00:06:07 GMT",
"2006-12-20 23:06:07 GMT",
"2006-12-20 23:06:07 GMT",
"2006-12-20 22:06:07 GMT",
"2006-12-20 22:06:07 GMT",
"2006-12-20 21:06:07 GMT",
"2006-06-20 17:06:07 GMT",
"2006-06-21 01:06:07 GMT",
"2006-06-21 00:06:07 GMT",
"2006-06-21 00:06:07 GMT",
"2006-06-20 23:06:07 GMT",
"2006-06-20 23:06:07 GMT",
"2006-06-20 22:06:07 GMT",
"2006-06-20 22:06:07 GMT",
"2006-06-20 21:06:07 GMT",
};
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
for (int i = 0; i < input.length; i++)
{
try
{
Date myDate = df.parse(input[i]);
String actual = df.format(myDate);
if (!expected[i].equals(actual))
{
System.out.println("Unable to parse <" + input[i] + "> expected "
+ expected[i] + " was " + actual);
}
}
catch (ParseException e)
{
e.printStackTrace();
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
use java 1.4.2_08