< prev index next >
src/share/classes/java/text/SimpleDateFormat.java
Print this page
*** 1629,1640 ****
}
return -start;
}
private int matchZoneString(String text, int start, String[] zoneNames) {
! for (int i = 1; i <= 4; ++i) {
! // Checking long and short zones [1 & 2],
// and long and short daylight [3 & 4].
String zoneName = zoneNames[i];
if (text.regionMatches(true, start,
zoneName, 0, zoneName.length())) {
return i;
--- 1629,1640 ----
}
return -start;
}
private int matchZoneString(String text, int start, String[] zoneNames) {
! for (int i = 0; i <= 4; ++i) {
! // Checking main zone[0], long and short zones [1 & 2],
// and long and short daylight [3 & 4].
String zoneName = zoneNames[i];
if (text.regionMatches(true, start,
zoneName, 0, zoneName.length())) {
return i;
*** 1655,1664 ****
--- 1655,1671 ----
}
/**
* find time zone 'text' matched zoneStrings and set to internal
* calendar.
+ * To fix the Bug 8141243, this method is slightly altered and works like this:
+ * If nameIndex is matching DST in zoneNames(i.e.nameIndex>2), then tz is assigned to the first timezone (at index 0),
+ * otherwise "tz" is assigned to the timzone at nameIndex in the zoneNames.This will make sure that,
+ * if any of the abbreviated timezones(like UTC,IST,PST,etc...) which is also part of the main timezone groups is set properly.
+ * Also, there is a special condition added for the other virtual timezones which are not part of the main timezones
+ * like AKST,ACST,AEST,WAT,etc.(i.e. "TimeZone.getTimeZone(zoneNames)" always returns "GMT" for those timezones),
+ * in which the timezone "tz" is always set to the first timezone in the group(at index 0).
*/
private int subParseZoneString(String text, int start, CalendarBuilder calb) {
boolean useSameName = false; // true if standard and daylight time use the same abbreviation.
TimeZone currentTimeZone = getTimeZone();
*** 1667,1709 ****
// Want to be able to parse both short and long forms.
int zoneIndex = formatData.getZoneIndex(currentTimeZone.getID());
TimeZone tz = null;
String[][] zoneStrings = formatData.getZoneStringsWrapper();
String[] zoneNames = null;
! int nameIndex = 0;
if (zoneIndex != -1) {
zoneNames = zoneStrings[zoneIndex];
! if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
! if (nameIndex <= 2) {
// Check if the standard name (abbr) and the daylight name are the same.
useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
}
tz = TimeZone.getTimeZone(zoneNames[0]);
}
}
if (tz == null) {
zoneIndex = formatData.getZoneIndex(TimeZone.getDefault().getID());
if (zoneIndex != -1) {
zoneNames = zoneStrings[zoneIndex];
! if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
! if (nameIndex <= 2) {
useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
}
tz = TimeZone.getTimeZone(zoneNames[0]);
}
}
}
if (tz == null) {
int len = zoneStrings.length;
for (int i = 0; i < len; i++) {
zoneNames = zoneStrings[i];
! if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
! if (nameIndex <= 2) {
useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
}
tz = TimeZone.getTimeZone(zoneNames[0]);
break;
}
}
}
if (tz != null) { // Matched any ?
--- 1674,1730 ----
// Want to be able to parse both short and long forms.
int zoneIndex = formatData.getZoneIndex(currentTimeZone.getID());
TimeZone tz = null;
String[][] zoneStrings = formatData.getZoneStringsWrapper();
String[] zoneNames = null;
! int nameIndex = -1;
if (zoneIndex != -1) {
zoneNames = zoneStrings[zoneIndex];
! if ((nameIndex = matchZoneString(text, start, zoneNames)) >= 0) {
! if (nameIndex > 0 && nameIndex < 3) {
// Check if the standard name (abbr) and the daylight name are the same.
useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
}
+ int index = (nameIndex <= 2) ? nameIndex : 0;
+ tz = TimeZone.getTimeZone(zoneNames[index]);
+ if (!("GMT".equals(currentTimeZone.getID()) || "GMT".equals(zoneNames[index]))
+ && "GMT".equals(tz.getID())) {
tz = TimeZone.getTimeZone(zoneNames[0]);
}
}
+ }
if (tz == null) {
zoneIndex = formatData.getZoneIndex(TimeZone.getDefault().getID());
if (zoneIndex != -1) {
zoneNames = zoneStrings[zoneIndex];
! if ((nameIndex = matchZoneString(text, start, zoneNames)) >= 0) {
! if (nameIndex > 0 && nameIndex < 3) {
useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
}
+ int index = (nameIndex <= 2) ? nameIndex : 0;
+ tz = TimeZone.getTimeZone(zoneNames[index]);
+ if (!("GMT".equals(TimeZone.getDefault().getID()) || "GMT".equals(zoneNames[index]))
+ && "GMT".equals(tz.getID())) {
tz = TimeZone.getTimeZone(zoneNames[0]);
}
}
}
+ }
if (tz == null) {
int len = zoneStrings.length;
for (int i = 0; i < len; i++) {
zoneNames = zoneStrings[i];
! if ((nameIndex = matchZoneString(text, start, zoneNames)) >= 0) {
! if (nameIndex > 0 && nameIndex < 3) {
useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
}
+ int index = (nameIndex <= 2) ? nameIndex : 0;
+ tz = TimeZone.getTimeZone(zoneNames[index]);
+ if (!("GMT".equals(zoneNames[0]) || "GMT".equals(zoneNames[index])) && "GMT".equals(tz.getID())) {
tz = TimeZone.getTimeZone(zoneNames[0]);
+ }
break;
}
}
}
if (tz != null) { // Matched any ?
*** 2073,2082 ****
--- 2094,2105 ----
}
if (sign == 0) { /* "GMT" without offset */
calb.set(Calendar.ZONE_OFFSET, 0)
.set(Calendar.DST_OFFSET, 0);
+ // set the timezone "GMT" to internal calendar, since it will not be set later.
+ setTimeZone(TimeZone.getTimeZone("GMT"));
return pos.index;
}
// Parse the rest as "hh:mm"
int i = subParseNumericZone(text, ++pos.index,
< prev index next >