private int parseNumericTemporal(String substring, Token token) {
    checkFormatExact(substring, token);

    // exceptions to the rule
    if (token.temporalField == ChronoField.AMPM_OF_DAY) {
      return substring.toLowerCase().startsWith("a") ? AM : PM;
    }
    if (token.temporalField == ChronoField.HOUR_OF_AMPM) {
      if ("12".equals(substring)) {
        return 0;
      }
      if ("0".equals(substring)) {
        throw new IllegalArgumentException("""
            Value of hour of day (hh/hh12) in input is 0. \
            The value should be between 1 and 12.\
            """);
      }
    }
    if (token.temporalField == ChronoField.YEAR
        || token.temporalField == IsoFields.WEEK_BASED_YEAR) {

      String currentYearString;
      if (token.temporalField == ChronoField.YEAR) {
        currentYearString = Integer.toString(this.now.or(LocalDateTime.now()).getYear());
      } else {
        currentYearString = Integer.toString(this.now.or(LocalDateTime.now()).get(IsoFields.WEEK_BASED_YEAR));
      }

      //deal with round years
      if (token.string.startsWith("r") && substring.length() == 2) {
        int currFirst2Digits = Integer.parseInt(currentYearString.substring(0, 2));
        int currLast2Digits = Integer.parseInt(currentYearString.substring(2));
        int valLast2Digits = Integer.parseInt(substring);
        if (valLast2Digits < 50 && currLast2Digits >= 50) {
          currFirst2Digits += 1;
        } else if (valLast2Digits >= 50 && currLast2Digits < 50) {
          currFirst2Digits -= 1;
        }
        substring = Integer.toString(currFirst2Digits) + substring;
      } else { // fill in prefix digits with current date
        substring = currentYearString.substring(0, 4 - substring.length()) + substring;
      }

    } else if (token.temporalField == ChronoField.NANO_OF_SECOND) {
      int i = Integer.min(token.length, substring.length());
      substring += StringUtils.repeat("0", NANOS_MAX_LENGTH - i);
    }

    // the rule
    try {
      return Integer.parseInt(substring);
    } catch (NumberFormatException e) {
      throw new IllegalArgumentException("Couldn't parse substring \"" + substring +
          "\" with token " + token + " to integer. Pattern is " + pattern, e);
    }
  }
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