public function date_sql_handler::views_formats in Date 7.3
Same name and namespace in other branches
- 5.2 date_api_sql.inc \date_sql_handler::views_formats()
- 6.2 date_api_sql.inc \date_sql_handler::views_formats()
- 6 date_api_sql.inc \date_sql_handler::views_formats()
- 7 date_api/date_api_sql.inc \date_sql_handler::views_formats()
- 7.2 date_api/date_api_sql.inc \date_sql_handler::views_formats()
@todo Document this.
File
- date_api/
date_api_sql.inc, line 948 - SQL helper for Date API.
Class
- date_sql_handler
- A class to manipulate date SQL.
Code
public function views_formats($granularity, $type = 'sql') {
if (empty($granularity)) {
return DATE_FORMAT_ISO;
}
$formats = array(
'display',
'sql',
);
// Start with the site long date format and add seconds to it.
$short = str_replace(':i', ':i:s', variable_get('date_format_short', 'l, F j, Y - H:i'));
switch ($granularity) {
case 'year':
$formats['display'] = 'Y';
$formats['sql'] = 'Y';
break;
case 'month':
$formats['display'] = date_limit_format($short, array(
'year',
'month',
));
$formats['sql'] = 'Y-m';
break;
case 'day':
$args = array(
'year',
'month',
'day',
);
$formats['display'] = date_limit_format($short, $args);
$formats['sql'] = 'Y-m-d';
break;
case 'hour':
$args = array(
'year',
'month',
'day',
'hour',
);
$formats['display'] = date_limit_format($short, $args);
$formats['sql'] = 'Y-m-d\\TH';
break;
case 'minute':
$args = array(
'year',
'month',
'day',
'hour',
'minute',
);
$formats['display'] = date_limit_format($short, $args);
$formats['sql'] = 'Y-m-d\\TH:i';
break;
case 'second':
$args = array(
'year',
'month',
'day',
'hour',
'minute',
'second',
);
$formats['display'] = date_limit_format($short, $args);
$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];
}