public static boolean isDate()

in api/src/main/java/com/google/appengine/api/search/query/ParserUtils.java [217:281]


  public static boolean isDate(CharSequence text) {
    if (text == null || text.length() == 0) {
      return false;
    }
    int year = 0;
    int i = 0;
    char c = '\0';
    if (text.charAt(i) == '-') {
      // Consume dash preceding year.
      i++;
    }
    while (i < text.length()) {
      c = text.charAt(i++);
      if (!Character.isDigit(c)) {
        break;
      }
      year = year * 10 + (c - '0');
      if (year > 9999) {
        return false;
      }
    }
    if (i >= text.length()) {
      return false;
    }
    if (c != '-') {
      return false;
    }
    int month = 0;
    while (i < text.length()) {
      c = text.charAt(i++);
      if (!Character.isDigit(c)) {
        break;
      }
      month = month * 10 + (c - '0');
      if (month > 12) {
        return false;
      }
    }
    if (month <= 0) {
      return false;
    }
    if (i >= text.length()) {
      return false;
    }
    if (c != '-') {
      return false;
    }
    int day = 0;
    while (i < text.length()) {
      c = text.charAt(i++);
      if (!Character.isDigit(c)) {
        return false;
      }
      day = day * 10 + (c - '0');
    }
    if (day <= 0) {
      return false;
    }
    if (month == 2) {
      if ((year % 400 == 0) || (year % 100 != 0 && year % 4 == 0)) {
        return day <= 29;
      }
    }
    return day <= MONTH_LENGTH[month - 1];
  }