You are here

function date_sql_handler::part_is_valid in Date 5.2

Same name and namespace in other branches
  1. 6.2 date_api_sql.inc \date_sql_handler::part_is_valid()
  2. 6 date_api_sql.inc \date_sql_handler::part_is_valid()
  3. 7.3 date_api/date_api_sql.inc \date_sql_handler::part_is_valid()
  4. 7 date_api/date_api_sql.inc \date_sql_handler::part_is_valid()
  5. 7.2 date_api/date_api_sql.inc \date_sql_handler::part_is_valid()

A function to test the validity of various date parts

File

./date_api_sql.inc, line 624

Class

date_sql_handler
A class to manipulate date SQL.

Code

function part_is_valid($value, $type) {
  if (!preg_match('/^[0-9]*$/', $value)) {
    return false;
  }
  $value = intval($value);
  if ($value <= 0) {
    return false;
  }
  switch ($type) {
    case 'year':
      if ($value < DATE_MIN_YEAR) {
        return false;
      }
      break;
    case 'month':
      if ($value < 0 || $value > 12) {
        return false;
      }
      break;
    case 'day':
      if ($value < 0 || $value > 31) {
        return false;
      }
      break;
    case 'week':
      if ($value < 0 || $value > 53) {
        return false;
      }
  }
  return true;
}