You are here

function _calendar_systems_get_granularity_from_time in Calendar Systems 7.2

Same name and namespace in other branches
  1. 8 calendar_systems.helpers.inc \_calendar_systems_get_granularity_from_time()
  2. 7 calendar_systems.helpers.inc \_calendar_systems_get_granularity_from_time()

Parameters

$time:

null $tz:

Return value

array

File

./calendar_systems.helpers.inc, line 7

Code

function _calendar_systems_get_granularity_from_time($time, $tz = NULL) {
  $granularity = array();
  $allgranularity = array(
    'year',
    'month',
    'day',
    'hour',
    'minute',
    'second',
    'timezone',
  );
  $temp = date_parse($time);

  // Special case for 'now'.
  if ($time == 'now') {
    $granularity = array(
      'year',
      'month',
      'day',
      'hour',
      'minute',
      'second',
    );
  }
  else {

    // This PHP date_parse() method currently doesn't have resolution down to
    // seconds, so if there is some time, all will be set.
    foreach ($allgranularity as $g) {
      if (isset($temp[$g]) && is_numeric($temp[$g]) || $g == 'timezone' && (isset($temp['zone_type']) && $temp['zone_type'] > 0)) {
        $granularity[] = $g;
      }
    }
  }
  if ($tz) {
    $granularity[] = 'timezone';
  }
  return $granularity;
}