if ((length = id.length()) < (GMT_ID_LENGTH + 2) ||
id.indexOf(GMT_ID) != 0) {
return null;
}
ZoneInfo zi;
// First, we try to find it in the cache with the given
// id. Even the id is not normalized, the returned ZoneInfo
// should have its normalized id.
zi = ZoneInfoFile.getZoneInfo(id);
if (zi != null) {
return zi;
}
int index = GMT_ID_LENGTH;
boolean negative = false;
char c = id.charAt(index++);
if (c == '-') {
negative = true;
} else if (c != '+') {
return null;
}
int hours = 0;
int num = 0;
int countDelim = 0;
int len = 0;
while (index < length) {
c = id.charAt(index++);
if (c == ':') {
if (countDelim > 0) {
return null;
}
if (len > 2) {
return null;
}
hours = num;
countDelim++;
num = 0;
len = 0;
continue;
}
if (c < '0' || c > '9') {
return null;
}
num = num * 10 + (c - '0');
len++;
}
if (index != length) {
return null;
}
if (countDelim == 0) {
if (len <= 2) {
hours = num;
num = 0;
} else {
hours = num / 100;
num %= 100;
}
} else {
if (len != 2) {
return null;
}
}
if (hours > 23 || num > 59) {
return null;
}
int gmtOffset = (hours * 60 + num) * 60 * 1000;
if (gmtOffset == 0) {
zi = ZoneInfoFile.getZoneInfo(GMT_ID);
if (negative) {
zi.setID("GMT-00:00");
} else {
zi.setID("GMT+00:00");
}
} else {
zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset);
}
return zi;