You are here

function date_range_value in Date 5

Validate and pad date range argument element

Parameters

$value - a full or partial ISO date from an argument: @param $value_type - min or max, whether it is the from or the to part of the range @return complete, validated ISO date

2 calls to date_range_value()
date_plus_period in ./date_views.inc
Compute min and max dates for a P value
date_views_date_range in ./date_views.inc

File

./date_views.inc, line 406

Code

function date_range_value($value, $value_type = 'min') {
  include_once drupal_get_path('module', 'date_api') . '/date.inc';
  $now = date_date(DATE_STRING_ISO, time());
  if (trim($value) == '@' || trim($value) == '') {
    return $now;
  }
  switch (strlen($value)) {
    case 4:
      $return = $value_type == 'min' ? $value . '-01-01T00:00:00' : $value . '-12-31T23:59:59';
      break;
    case 7:
      $return = $value_type == 'min' ? $value . '-01T00:00:00' : $value . '-31T23:59:59';
      break;
    case 10:
      $return = $value_type == 'min' ? $value . 'T00:00:00' : $value . 'T23:59:59';
      break;
    case 13:
      $return = $value_type == 'min' ? $value . ':00:00' : $value . ':59:59';
      break;
    case 16:
      $return = $value_type == 'min' ? $value . ':00' : $value . ':59';
      break;
    case 19:
      $return = $value;
      break;
    default:
      $return = $now;
  }

  // use date_preg to test for validity of constructed date
  return date_preg($return) ? $return : $now;
}