JDK-6644494 : [Fmt-Da] SimpleDateFormat do not use timezone historic offset change during parsing
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-12-20
  • Updated: 2010-07-29
  • Resolved: 2007-12-26
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_10"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_10-b03)
Java HotSpot(TM) Client VM (build 1.5.0_10-b03, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Window XP

A DESCRIPTION OF THE PROBLEM :
SimpleDateFormat use current timezone offset when parsing a date with Timezone and not the offset of the timezone at the parsed date.

See : method SDF.subParseZoneString when tz != null => use of tz.getRawOffset().

A consequence of this is that date before 1940 with tz Europe/Paris "loose" one hour each time it's parsed :

INFO: Date_object_1 init			: Tue Feb 11 00:00:00 CET 1936
INFO: Date_str_1 formated from Date_object_1	: 1936-02-11 00:00:00.0 CET
INFO: Date_object_2 parsed from Date_str_1	: Mon Feb 10 23:00:00 CET 1936
INFO: Date_str_2 formated from Date_object_2	: 1936-02-10 23:00:00.0 CET
INFO: Date_object_3 parsed from Date_str_2	: Mon Feb 10 22:00:00 CET 1936



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Set host TZ to Europe/Paris and execute testcase provided.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class DateFormatTest extends TestCase {

	Logger logger = Logger.getLogger("");

	public void testParseDateBefore1940Cet() throws ParseException {
		String dateStr = "1936-02-11";

		DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");
		df1.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
		Date d1 = df1.parse(dateStr);
		logger.info("Date_object_1 init					: " + d1.toString());

		DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S zzz");
		df2.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));

		String str = df2.format(d1);
		logger.info("Date_str_1 formated from Sate_object_1			: " + str);

		d1 = df2.parse(str);
		logger.info("Date_object_2 parsed from Sate_str_1			: " + d1);

		str = df2.format(d1);
		logger.info("Date_str_2 formated from Sate_object_2			: " + str);

		d1 = df2.parse(str);
		logger.info("Date_object_3 parsed from Date_str_2			: " + d1);

	}

}
---------- END SOURCE ----------

Comments
EVALUATION This is a known issue. Closing this CR as a duplicate of 4255109.
26-12-2007