1 date_sql_handler.inc | date_sql_handler::views_formats($granularity, $type = 'sql') |
@todo.
File
- core/
modules/ date/ views/ date_sql_handler.inc, line 625 - SQL helper for Date API.
Class
- date_sql_handler
- A class to manipulate date SQL.
Code
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.
$shortformat = system_date_format_load('short');
$short = str_replace(':i', ':i:s', $shortformat['pattern']);
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];
}