You are here

function date_is_valid in Date 5

Same name and namespace in other branches
  1. 5.2 date_api.module \date_is_valid()
  2. 6.2 date_api.module \date_is_valid()
  3. 6 date_api.module \date_is_valid()

Functions to test the validity of various date parts

Parameters

$format could be 'array', DATE_UNIX, or DATE_ISO:

8 calls to date_is_valid()
date_array2iso in ./date.inc
Date conversion functions
date_array2unix in ./date.inc
date_field in ./date.module
Implementation of hook_field().
date_iso2array in ./date.inc
date_iso2unix in ./date.inc

... See full list

File

./date.inc, line 1557
Date/time API functions

Code

function date_is_valid($value, $format) {
  switch ($format) {
    case 'array':
      if (!date_part_is_valid($value['year'], 'year') || !date_part_is_valid($value['mon'], 'mon') || !date_part_is_valid($value['mday'], 'mday')) {
        return FALSE;
      }
      return TRUE;
    case DATE_UNIX:
      if (!date_part_is_valid(date_unix_year($value), 'year') || !date_part_is_valid(date_unix_mon($value), 'mon', 1) || !date_part_is_valid(date_unix_day($value), 'mday', 1)) {
        return FALSE;
      }
      return TRUE;
    default:
      if (!date_part_is_valid(date_iso_year($value), 'year') || !date_part_is_valid(date_iso_mon($value), 'mon') || !date_part_is_valid(date_iso_day($value), 'mday')) {
        return FALSE;
      }
      return TRUE;
  }
}