United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6645292 [Fmt-Da] Timezone Western Summer Time (Australia) is parsed incorrectly
JDK-6645292 : [Fmt-Da] Timezone Western Summer Time (Australia) is parsed incorrectly

Details
Type:
Bug
Submit Date:
2007-12-25
Status:
Closed
Updated Date:
2011-03-08
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
core-libs
OS:
solaris,windows_xp
Sub-Component:
java.text
CPU:
x86,generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
1.4.2,5.0
Fixed Versions:

Related Reports
Backport:
Backport:
Backport:
Backport:
Backport:
Backport:

Sub Tasks

Description
FULL PRODUCT VERSION :
j2re1.4.2_13

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
After introduction of Daylight Savings Time in Western Australia, I used the Timezone Updater Tool to update the timezones. I got incorrect results parsing and formatting times in this timezone.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the Timezone Updater Tool to make sure the latest timezones are available
2. Run Test code below for timezones Australia/Perth and compare running it for Australia/Melbourne

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Output:
Success
ACTUAL -
Output:
20071112020000 Coordinated Universal Time -> 20071112110000 Western Summer Time (Australia) in DST
20071112030000 Coordinated Universal Time
since epoch before: 1194832800000 since epoch after 1194836400000

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public void testSimple()
	{
		TimeZone tz = TimeZone.getTimeZone("Australia/Perth");
		//TimeZone tz = TimeZone.getTimeZone("Australia/Melbourne");
		TimeZone utcTZ = TimeZone.getTimeZone("UTC");
		SimpleDateFormat f = new SimpleDateFormat("yyyyMMddHHmmss zzzz");
		f.setTimeZone(tz);
		String time = "20071112020000 Coordinated Universal Time";
		SimpleDateFormat utcFormatter = new SimpleDateFormat("yyyyMMddHHmmss zzzz");
		utcFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
		String output;
		Date date;
		String dateS;
		boolean inDST;
		long sinceEpoch1;
		long sinceEpoch2;
		try {
			output = time;
			date = utcFormatter.parse(time);
			sinceEpoch1 = date.getTime();
			dateS = f.format(date);
			output += " -> " + dateS;
			inDST = tz.inDaylightTime(date);
			if (!inDST) {
				output += " not";
			}
			output +=" in DST";
			date = f.parse(dateS);
			sinceEpoch2 = date.getTime();
			f.setTimeZone(utcTZ);
			dateS = utcFormatter.format(date);
			output += "\n" + dateS;
			if (!dateS.equals(time)) {
				output += "\nsince epoch before: " +
					sinceEpoch1 + " since epoch after " +
					sinceEpoch2;
				System.out.println(output);
			} else {
				System.out.println("Success");
			}
		} catch (ParseException e) {
			e.printStackTrace(System.err);
		}
	}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Have not found a workaround.

                                    

Comments
EVALUATION

SimpleDateFormat.parse() calls TimeZone.getDSTSavings() to get the daylight saving time amount to let a Calendar calculate the given local time. However, TimeZone.getDSTSavings() returns 0 for Australia/Perth because its last DST rule doesn't observe daylight saving time (it's a 3-year trial for observing DST).

We could let the Calendar calculate the local time from the given TimeZone object. However, this change will involve some incompatible changes in other time zones.
                                     
2007-12-25



Hardware and Software, Engineered to Work Together