function date_part_is_valid in Date 5
Function to test validity of specific date part
Parameters
$value - the value to test: @param $part - the type of date part provided, coult be 'year', 'mon', or 'mday' @parma $min either 0 or 1, use to set min for mon and mday can be 0 for iso dates, set to 1 for unix timestamps that require a complete date
3 calls to date_part_is_valid()
- date_is_valid in ./
date.inc - Functions to test the validity of various date parts
- date_selector_validate in ./
date.inc - Validation function for date selector $params = an array of values including: required = is a valid date required, default is true opt_fields = an array of fields that need not be filled out, default is empty array
- date_text2iso in ./
date.inc - Use stringtotime function to create an iso date out of text
File
- ./
date.inc, line 1579 - Date/time API functions
Code
function date_part_is_valid($value, $part, $min = 0) {
switch ($part) {
case 'year':
if ($value < DATE_MIN_YEAR || $value > DATE_MAX_YEAR) {
return FALSE;
}
break;
case 'mon':
if ($value < $min || $value > 12) {
return FALSE;
}
break;
case 'mday':
if ($value < $min || $value > 31) {
return FALSE;
}
break;
case 'week':
if ($value < 0 || $value > 53) {
return FALSE;
}
break;
}
return TRUE;
}