You are here

function date_sql_handler::views_formats in Date 7

Same name and namespace in other branches
  1. 5.2 date_api_sql.inc \date_sql_handler::views_formats()
  2. 6.2 date_api_sql.inc \date_sql_handler::views_formats()
  3. 6 date_api_sql.inc \date_sql_handler::views_formats()
  4. 7.3 date_api/date_api_sql.inc \date_sql_handler::views_formats()
  5. 7.2 date_api/date_api_sql.inc \date_sql_handler::views_formats()

File

date_api/date_api_sql.inc, line 656
SQL helper for Date API.

Class

date_sql_handler
A class to manipulate date SQL.

Code

function views_formats($granularity, $type = 'sql') {
  $formats = array(
    'display',
    'sql',
  );

  // Start with the site long date format and add seconds to it
  $long = str_replace(':i', ':i:s', variable_get('date_format_long', 'l, F j, Y - H:i'));
  switch ($granularity) {
    case 'year':
      $formats['display'] = 'Y';
      $formats['sql'] = 'Y';
      break;
    case 'month':
      $formats['display'] = date_limit_format($long, array(
        'year',
        'month',
      ));
      $formats['sql'] = 'Y-m';
      break;
    case 'day':
      $formats['display'] = date_limit_format($long, array(
        'year',
        'month',
        'day',
      ));
      $formats['sql'] = 'Y-m-d';
      break;
    case 'hour':
      $formats['display'] = date_limit_format($long, array(
        'year',
        'month',
        'day',
        'hour',
      ));
      $formats['sql'] = 'Y-m-d\\TH';
      break;
    case 'minute':
      $formats['display'] = date_limit_format($long, array(
        'year',
        'month',
        'day',
        'hour',
        'minute',
      ));
      $formats['sql'] = 'Y-m-d\\TH:i';
      break;
    case 'second':
      $formats['display'] = date_limit_format($long, array(
        'year',
        'month',
        'day',
        'hour',
        'minute',
        'second',
      ));
      $formats['sql'] = 'Y-m-d\\TH:i:s';
      break;
    case 'week':
      $formats['display'] = 'F j Y (W)';
      $formats['sql'] = 'Y-\\WW';
      break;
  }
  return $formats[$type];
}