You are here

function partial_date_year_designation_decorator in Partial Date 7

Decorates a year with the given year designations.

As there is no year 0, so an empty year will return an empty string.

1 call to partial_date_year_designation_decorator()
partial_date_format_component in ./partial_date.module

File

./partial_date.module, line 1219
Defines a date element that allows for any combination of date granularity settings.

Code

function partial_date_year_designation_decorator($year, $designation = 'ce') {
  static $designation_suffixes;
  if (empty($designation_suffixes)) {
    $designation_suffixes = array(
      'BC' => t('BC', array(), array(
        'context' => 'datetime',
      )),
      'AD' => t('AD', array(), array(
        'context' => 'datetime',
      )),
      'BCE' => t('BCE', array(), array(
        'context' => 'datetime',
      )),
      'CE' => t('CE', array(), array(
        'context' => 'datetime',
      )),
    );
  }
  if (empty($year) || !is_numeric($year)) {
    return '';
  }
  switch ($designation) {
    case 'ce':
      return $year > 0 ? $designation_suffixes['CE'] : $designation_suffixes['BCE'];
    case 'bce':
      return $year > 0 ? '' : $designation_suffixes['BCE'];
    case 'ad':
      return $year > 0 ? $designation_suffixes['AD'] : $designation_suffixes['BC'];
    case 'bc':
      return $year > 0 ? '' : $designation_suffixes['BC'];
    case 'sign':
    default:
      return '';
  }
}