docs: private static Date parse(String date, ParsePosition pos) throws ParseException {
      Exception fail = null;
      try {
        int offset = pos.getIndex();
  
        // extract year
        int year = parseInt(date, offset, offset += 4);
        if (checkOffset(date, offset, '-')) {
          offset += 1;
        }
  
        // extract month
        int month = parseInt(date, offset, offset += 2);
        if (checkOffset(date, offset, '-')) {
          offset += 1;
        }
  
        // extract day
        int day = parseInt(date, offset, offset += 2);
        // default time value
        int hour = 0;
        int minutes = 0;
        int seconds = 0;
        int milliseconds = 0; // always use 0 otherwise returned date will include millis of current time
        if (checkOffset(date, offset, 'T')) {
  
          // extract hours, minutes, seconds and milliseconds
          hour = parseInt(date, offset += 1, offset += 2);
          if (checkOffset(date, offset, ':')) {
            offset += 1;
          }
  
          minutes = parseInt(date, offset, offset += 2);
          if (checkOffset(date, offset, ':')) {
            offset += 1;
          }
          // second and milliseconds can be optional
          if (date.length() > offset) {
            char c = date.charAt(offset);
            if (c != 'Z' && c != '+' && c != '-') {
              seconds = parseInt(date, offset, offset += 2);
              // milliseconds can be optional in the format
              if (checkOffset(date, offset, '.')) {
                milliseconds = parseInt(date, offset += 1, offset += 3);
              }
            }
          }
        }
  
        // extract timezone
        String timezoneId;
        if (date.length() <= offset) {
          throw new IllegalArgumentException("No time zone indicator");
        }
        char timezoneIndicator = date.charAt(offset);
        if (timezoneIndicator == '+' || timezoneIndicator == '-') {
          String timezoneOffset = date.substring(offset);
          timezoneId = GMT_ID + timezoneOffset;
          offset += timezoneOffset.length();
        } else if (timezoneIndicator == 'Z') {
          timezoneId = GMT_ID;
          offset += 1;
        } else {
          throw new IndexOutOfBoundsException("Invalid time zone indicator " + timezoneIndicator);
        }
  
        TimeZone timezone = TimeZone.getTimeZone(timezoneId);
        if (!timezone.getID().equals(timezoneId)) {
          throw new IndexOutOfBoundsException();
        }
  
        Calendar calendar = new GregorianCalendar(timezone);
        calendar.setLenient(false);
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, month - 1);
        calendar.set(Calendar.DAY_OF_MONTH, day);
        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, minutes);
        calendar.set(Calendar.SECOND, seconds);
        calendar.set(Calendar.MILLISECOND, milliseconds);
  
        pos.setIndex(offset);
        return calendar.getTime();
        // If we get a ParseException it'll already have the right message/offset.
        // Other exception types can convert here.
      } catch (IndexOutOfBoundsException e) {
        fail = e;
      } catch (NumberFormatException e) {
        fail = e;
      } catch (IllegalArgumentException e) {
        fail = e;
      }
      String input = (date == null) ? null : ("'" + date + "'");
      throw new ParseException("Failed to parse date [" + input + "]: " + fail.getMessage(), pos.getIndex());
    }