You are here

function date_sql_handler::views_formats in Date 5.2

Same name and namespace in other branches
  1. 6.2 date_api_sql.inc \date_sql_handler::views_formats()
  2. 6 date_api_sql.inc \date_sql_handler::views_formats()
  3. 7.3 date_api/date_api_sql.inc \date_sql_handler::views_formats()
  4. 7 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()

Default format strings for PHP and SQL.

The SQL version is converted to the right format for the database in sql_format().

File

./date_api_sql.inc, line 652

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 'date':
      $formats['display'] = $long;
      $formats['sql'] = 'Y-m-d H:i:s';
      break;
    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];
}