in asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/temporal/ATimeParserFactory.java [66:160]
public static int parseTimePart(String timeString, int start, int length) throws HyracksDataException {
int offset = 0;
int hour = 0, min = 0, sec = 0, millis = 0;
int timezone = 0;
boolean isExtendedForm = false;
if (timeString.charAt(start + offset + 2) == ':') {
isExtendedForm = true;
}
if (isExtendedForm
&& (timeString.charAt(start + offset + 2) != ':' || timeString.charAt(start + offset + 5) != ':')) {
throw new HyracksDataException(timeErrorMessage + ": Missing colon in an extended time format.");
}
// hour
for (int i = 0; i < 2; i++) {
if ((timeString.charAt(start + offset + i) >= '0' && timeString.charAt(start + offset + i) <= '9')) {
hour = hour * 10 + timeString.charAt(start + offset + i) - '0';
} else {
throw new HyracksDataException(timeErrorMessage + ": Non-numeric value in hour field");
}
}
if (hour < GregorianCalendarSystem.FIELD_MINS[GregorianCalendarSystem.Fields.HOUR.ordinal()]
|| hour > GregorianCalendarSystem.FIELD_MAXS[GregorianCalendarSystem.Fields.HOUR.ordinal()]) {
throw new HyracksDataException(timeErrorMessage + ": hour " + hour);
}
offset += (isExtendedForm) ? 3 : 2;
// minute
for (int i = 0; i < 2; i++) {
if ((timeString.charAt(start + offset + i) >= '0' && timeString.charAt(start + offset + i) <= '9')) {
min = min * 10 + timeString.charAt(start + offset + i) - '0';
} else {
throw new HyracksDataException(timeErrorMessage + ": Non-numeric value in minute field");
}
}
if (min < GregorianCalendarSystem.FIELD_MINS[GregorianCalendarSystem.Fields.MINUTE.ordinal()]
|| min > GregorianCalendarSystem.FIELD_MAXS[GregorianCalendarSystem.Fields.MINUTE.ordinal()]) {
throw new HyracksDataException(timeErrorMessage + ": min " + min);
}
offset += (isExtendedForm) ? 3 : 2;
// second
for (int i = 0; i < 2; i++) {
if ((timeString.charAt(start + offset + i) >= '0' && timeString.charAt(start + offset + i) <= '9')) {
sec = sec * 10 + timeString.charAt(start + offset + i) - '0';
} else {
throw new HyracksDataException(timeErrorMessage + ": Non-numeric value in second field");
}
}
if (sec < GregorianCalendarSystem.FIELD_MINS[GregorianCalendarSystem.Fields.SECOND.ordinal()]
|| sec > GregorianCalendarSystem.FIELD_MAXS[GregorianCalendarSystem.Fields.SECOND.ordinal()]) {
throw new HyracksDataException(timeErrorMessage + ": sec " + sec);
}
offset += 2;
if ((isExtendedForm && length > offset && timeString.charAt(start + offset) == '.')
|| (!isExtendedForm && length > offset)) {
offset += (isExtendedForm) ? 1 : 0;
int i = 0;
for (; i < 3 && offset + i < length; i++) {
if (timeString.charAt(start + offset + i) >= '0' && timeString.charAt(start + offset + i) <= '9') {
millis = millis * 10 + timeString.charAt(start + offset + i) - '0';
} else {
break;
}
}
offset += i;
for (; i < 3; i++) {
millis = millis * 10;
}
// error is thrown if more than three digits are seen for the millisecond part
if (length > offset && timeString.charAt(start + offset) >= '0'
&& timeString.charAt(start + offset) <= '9') {
throw new HyracksDataException(timeErrorMessage + ": too many fields for millisecond.");
}
}
if (length > offset) {
parseTimezonePart(timeString, start + offset); // parsed, then ignored
}
return GregorianCalendarSystem.getInstance().getChronon(hour, min, sec, millis);
}