You are here

function datex_date_formatter_dates_alter in Datex 7.2

Same name and namespace in other branches
  1. 7.3 datex_date.inc \datex_date_formatter_dates_alter()

Implemetns hook_date_formatter_dates_alter().

Converts gregorian date to Jalali date before display (such as node view).

File

./datex_date.inc, line 66
Provides Jalali support for date module.

Code

function datex_date_formatter_dates_alter(&$dates, $context) {
  if (isset($context['display']['settings']['datex_schema'])) {
    $schema = $context['display']['settings']['datex_schema'];
  }
  else {
    $schema = 'default';
  }
  $tz = $dates['value']['local']['timezone'];
  $g = array_values($context['field']['settings']['granularity']);
  foreach ($g as $index => $value) {
    if ($value === 0) {
      unset($g[$index]);
    }
  }
  if (!($calendar = _datex_field_calendar($g, $schema, $tz))) {
    return;
  }
  foreach ($dates as $name => &$date) {
    $calendar
      ->setTimestamp($date['local']['object']
      ->format('U'));
    $calendar
      ->fixByGranularities($context['field']['settings']['granularity']);
    $calendar
      ->setTime((int) $date['local']['object']
      ->format('G'), (int) $date['local']['object']
      ->format('i'), (int) $date['local']['object']
      ->format('s'));
    $dates[$name]['formatted'] = $calendar
      ->format($context['format']);
  }
}