I need an very important feature for the date type form field. This feature is the variable year interval.
I implement this feature. This need very few modify on expand_date() function:

// this function is the form.inc file, but i modify some line:
function expand_date($element) {
	// Default to current date

  if (!isset($element['#value'])) {
    $element['#value'] = array('day' => format_date(time(), 'custom', 'j'),
                            'month' => format_date(time(), 'custom', 'n'),
                            'year' => format_date(time(), 'custom', 'Y'));
  }

  $element['#tree'] = TRUE;

  // Determine the order of day, month, year in the site's chosen date format.
  $format = variable_get('date_format_short', 'm/d/Y');
  $sort = array();
  $sort['day'] = max(strpos($format, 'd'), strpos($format, 'j'));
  $sort['month'] = max(strpos($format, 'm'), strpos($format, 'M'));
  $sort['year'] = strpos($format, 'Y');
  asort($sort);
  $order = array_keys($sort);

  
// these lines added
  $start_year = 1900;
  $end_year = 2050;
  if ($element['#start_year']) {
  	$start_year = $element['#start_year'];
  }
  if ($element['#end_year']) {
  	$end_year = $element['#end_year'];
  }
// end new lines


  // Output multi-selector for date
  foreach ($order as $type) {
    switch ($type) {
      case 'day':
        $options = drupal_map_assoc(range(1, 31));
        break;
      case 'month':
        $options = drupal_map_assoc(range(1, 12), 'map_month');
        break;
      case 'year':
        $options = drupal_map_assoc(range($start_year, $end_year)); // this line was fix range
        break;
    }
    $parents = $element['#parents'];
    $parents[] = $type;
    $element[$type] = array(
      '#type' => 'select',
      '#value' => $element['#value'][$type],
      '#attributes' => $element['#attributes'],
      '#options' => $options,
    );
  }

  return $element;
}

I hope the developers will add this feature to the 4.7 drupal.

Thank you for reading this post.

Comments

thamizhg’s picture

thanks....

With Regards,
G.ThamizhSelvan.