You are here

function date_sql_handler::date_parts in Date 7

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

An array of all date parts, optionally limited to an array of allowed parts.

2 calls to date_sql_handler::date_parts()
date_sql_handler::complete_date in date_api/date_api_sql.inc
Create a complete datetime value out of an incomplete array of selected values.
date_sql_handler::granularity_form in date_api/date_api_sql.inc

File

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

Class

date_sql_handler
A class to manipulate date SQL.

Code

function date_parts($limit = NULL) {
  $parts = array(
    'year' => t('Year', array(), array(
      'context' => 'datetime',
    )),
    'month' => t('Month', array(), array(
      'context' => 'datetime',
    )),
    'day' => t('Day', array(), array(
      'context' => 'datetime',
    )),
    'hour' => t('Hour', array(), array(
      'context' => 'datetime',
    )),
    'minute' => t('Minute', array(), array(
      'context' => 'datetime',
    )),
    'second' => t('Second', array(), array(
      'context' => 'datetime',
    )),
  );
  if (!empty($limit)) {
    $last = FALSE;
    foreach ($parts as $key => $part) {
      if ($last) {
        unset($parts[$key]);
      }
      if ($key == $limit) {
        $last = TRUE;
      }
    }
  }
  return $parts;
}