You are here

function DateSqlHandler::date_parts in Date 8

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

2 calls to DateSqlHandler::date_parts()
DateSqlHandler::complete_date in date_api/lib/Drupal/date_api/DateSqlHandler.php
Create a complete datetime value out of an incomplete array of selected values.
DateSqlHandler::granularity_form in date_api/lib/Drupal/date_api/DateSqlHandler.php
@todo.

File

date_api/lib/Drupal/date_api/DateSqlHandler.php, line 619

Class

DateSqlHandler
A class to manipulate date SQL.

Namespace

Drupal\date_api

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;
}