You are here

function date_range_string in Date 8

Same name and namespace in other branches
  1. 6.2 date_api.module \date_range_string()
  2. 7.3 date_api/date_api.module \date_range_string()
  3. 7 date_api/date_api.module \date_range_string()
  4. 7.2 date_api/date_api.module \date_range_string()

Converts a min and max year into a string like '-3:+1'.

Parameters

array $years: A numerically indexed array, containing a minimum and maximum year.

Return value

string A min and max year string like '-3:+1'.

File

date_api/date_api.module, line 417
This module will make the date API available to other modules. Designed to provide a light but flexible assortment of functions and constants, with more functionality in additional files that are not loaded unless other modules specifically include them.

Code

function date_range_string($years) {
  $this_year = date_format(new DrupalDateTime(), 'Y');
  if ($years[0] < $this_year) {
    $min = '-' . ($this_year - $years[0]);
  }
  else {
    $min = '+' . ($years[0] - $this_year);
  }
  if ($years[1] < $this_year) {
    $max = '-' . ($this_year - $years[1]);
  }
  else {
    $max = '+' . ($years[1] - $this_year);
  }
  return $min . ':' . $max;
}