ICU-5895 Fix a timezone string parsing problem in SimpleDateFormat. When zone string is DateFormatSymbols.TIMEZONE_XXXX_STANDARD or TIMEZONE_XXXX_DAYLIGHT, parsed time zone was not set in the calendar by parse method.
X-SVN-Rev: 22572
This commit is contained in:
parent
45f5c60bb7
commit
b696e36f7b
@ -278,6 +278,9 @@ public class SimpleDateFormat extends DateFormat {
|
||||
|
||||
private transient TimeZone parsedTimeZone;
|
||||
|
||||
//TODO: This is a temporary workaround for zone parsing problem
|
||||
private transient boolean isTimeZoneOffsetSet;
|
||||
|
||||
private static final int millisPerHour = 60 * 60 * 1000;
|
||||
private static final int millisPerMinute = 60 * 1000;
|
||||
|
||||
@ -1300,6 +1303,7 @@ public class SimpleDateFormat extends DateFormat {
|
||||
|
||||
// hack, clear parsedTimeZone
|
||||
parsedTimeZone = null;
|
||||
isTimeZoneOffsetSet = false;
|
||||
|
||||
// item index for the first numeric field within a countiguous numeric run
|
||||
int numericFieldStart = -1;
|
||||
@ -1458,14 +1462,16 @@ public class SimpleDateFormat extends DateFormat {
|
||||
if (parsedTimeZone != null) {
|
||||
TimeZone tz = parsedTimeZone;
|
||||
|
||||
// the calendar represents the parse as gmt time
|
||||
// we need to turn this into local time, so we add the raw offset
|
||||
// then we ask the timezone to handle this local time
|
||||
int[] offsets = new int[2];
|
||||
tz.getOffset(copy.getTimeInMillis()+tz.getRawOffset(), true, offsets);
|
||||
|
||||
cal.set(Calendar.ZONE_OFFSET, offsets[0]);
|
||||
cal.set(Calendar.DST_OFFSET, offsets[1]);
|
||||
if (!isTimeZoneOffsetSet) {
|
||||
// the calendar represents the parse as gmt time
|
||||
// we need to turn this into local time, so we add the raw offset
|
||||
// then we ask the timezone to handle this local time
|
||||
int[] offsets = new int[2];
|
||||
tz.getOffset(copy.getTimeInMillis()+tz.getRawOffset(), true, offsets);
|
||||
|
||||
cal.set(Calendar.ZONE_OFFSET, offsets[0]);
|
||||
cal.set(Calendar.DST_OFFSET, offsets[1]);
|
||||
}
|
||||
cal.setTimeZone(tz);
|
||||
}
|
||||
}
|
||||
@ -1605,20 +1611,24 @@ public class SimpleDateFormat extends DateFormat {
|
||||
|| type == DateFormatSymbols.TIMEZONE_LONG_STANDARD) {
|
||||
// standard time
|
||||
cal.set(Calendar.DST_OFFSET, 0);
|
||||
tz = null;
|
||||
isTimeZoneOffsetSet = true;
|
||||
} else if (type == DateFormatSymbols.TIMEZONE_SHORT_DAYLIGHT
|
||||
|| type == DateFormatSymbols.TIMEZONE_LONG_DAYLIGHT) {
|
||||
// daylight time
|
||||
// use the correct DST SAVINGS for the zone.
|
||||
// cal.set(UCAL_DST_OFFSET, tz->getDSTSavings());
|
||||
cal.set(Calendar.DST_OFFSET, millisPerHour);
|
||||
tz = null;
|
||||
} else {
|
||||
// either standard or daylight
|
||||
// need to finish getting the date, then compute dst offset as
|
||||
// appropriate
|
||||
parsedTimeZone = tz;
|
||||
isTimeZoneOffsetSet = true;
|
||||
}
|
||||
// else {
|
||||
// // either standard or daylight
|
||||
// // need to finish getting the date, then compute dst offset as
|
||||
// // appropriate
|
||||
// parsedTimeZone = tz;
|
||||
// }
|
||||
//TODO: revisit this after 3.8
|
||||
// Always set parsedTimeZone, otherwise, the time zone is never set to the result calendar
|
||||
parsedTimeZone = tz;
|
||||
if(value != null) {
|
||||
return start + value.length();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user