public static LocalTime parse(CharSequence text) {

    int length = text.length();
    int errorIndex = 0;
    Throwable cause = null;
    try {
      // "HH:mm".length() == 5, "HH:mm:ss".length() == 8, "HH:mm:ss.SSS".length() == 12,
      // "HH:mm:ss.SSSSSS".length() == 15, "HH:mm:ss.SSSSSSSSS".length()==18
      if (((length == 5) || ((length >= 8) && (length <= 18))) && (text.charAt(2) == ':')) {
        String hourString = text.subSequence(0, 2).toString();
        int hour = Integer.parseInt(hourString);
        errorIndex = 3;
        String minuteString = text.subSequence(3, 5).toString();
        int minute = Integer.parseInt(minuteString);
        int second = 0;
        int nano = 0;
        // "HH:mm:ss".length() == 8
        if (length >= 8) {
          if (text.charAt(5) != ':') {
            errorIndex = 5;
            throw new IllegalArgumentException(text.toString());
          }
          errorIndex = 6;
          String secondString = text.subSequence(6, 8).toString();
          second = Integer.parseInt(secondString);
          // "HH:mm:ss.SSS".length() == 12, "HH:mm:ss.SSSSSSSSS".length()==18
          if (length >= 10) {
            if (text.charAt(8) != '.') {
              errorIndex = 8;
              throw new IllegalArgumentException(text.toString());
            }
            errorIndex = 9;
            String nanoString = text.subSequence(9, length).toString();
            nano = Integer.parseInt(nanoString);
            int factor = NANO_FACTORS[nanoString.length()];
            nano = nano * factor;
          }
        }
        return of(hour, minute, second, nano);
      }
    } catch (RuntimeException e) {
      cause = e;
    }
    throw new DateTimeParseException("Expected format HH:mm:ss.SSSSSSSSS", text, errorIndex, cause);
  }