private String getNextCharacterSubstring(String fullInput, int index, Token token) {
    int end = index + token.length;
    if (end > fullInput.length()) {
      end = fullInput.length();
    }
    String substring = fullInput.substring(index, end);
    if (token.length == 3) { //dy, mon
      return substring;
    }

    // patterns day, month
    String regex;
    if (token.temporalField == ChronoField.MONTH_OF_YEAR) {
      regex = MONTH_REGEX;
    } else if (token.temporalField == ChronoField.DAY_OF_WEEK) {
      regex = DAY_OF_WEEK_REGEX;
    } else {
      throw new IllegalArgumentException("Error at index " + index + ": " + token + " not a "
          + "character temporal with length not 3");
    }
    Matcher matcher = Pattern.compile(regex, Pattern.CASE_INSENSITIVE).matcher(substring);
    if (matcher.find()) {
      return substring.substring(0, matcher.end());
    }
    throw new IllegalArgumentException(
        "Couldn't find " + token.string + " in substring " + substring + " at index " + index);
  }
Get the integer value of a numeric temporal substring.

@param substring the next parseable substring of the input string
@param token Token representing the next element of the pattern
@return int value of temporal
@throws IllegalArgumentException if substring is not parseable or if its value is outside of
token's allowed range (e.g. token is hh/hh12 (range: 1-12) and substring is "0")
common/src/java/org/apache/hadoop/hive/common/format/datetime/HiveSqlDateTimeFormatter.java