You are here

function date_granularity_format in Date 6.2

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

Construct an appropriate DATETIME format string for the granularity of an item.

File

./date_api.module, line 517
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_granularity_format($granularity) {
  if (is_array($granularity)) {
    $granularity = date_granularity_precision($granularity);
  }
  $format = 'Y-m-d H:i:s';
  switch ($granularity) {
    case 'year':
      return drupal_substr($format, 0, 1);
    case 'month':
      return drupal_substr($format, 0, 3);
    case 'day':
      return drupal_substr($format, 0, 5);
    case 'hour':
      return drupal_substr($format, 0, 7);
    case 'minute':
      return drupal_substr($format, 0, 9);
    default:
      return $format;
  }
}