You are here

function date_format_order in Date 6.2

Same name and namespace in other branches
  1. 8 date_api/date_api.module \date_format_order()
  2. 5.2 date_api.module \date_format_order()
  3. 6 date_api.module \date_format_order()
  4. 7.3 date_api/date_api.module \date_format_order()
  5. 7 date_api/date_api.module \date_format_order()
  6. 7.2 date_api/date_api.module \date_format_order()

Convert a format to an ordered array of granularity parts.

Example: date_format_order('m/d/Y H:i') returns array( 0 => 'month', 1 => 'day', 2 => 'year', 3 => 'hour', 4 => 'minute', );

Parameters

string $format:

Return value

array of ordered granularity elements in this format string

9 calls to date_format_order()
date_combo_validate in date/date_elements.inc
Validate and update a combo element. Don't try this if there were errors before reaching this point.
date_parts_element in ./date_api_elements.inc
Create form elements for one or more date parts.
date_popup_input_value in date_popup/date_popup.module
Helper function for extracting a date value out of user input.
date_popup_process in date_popup/date_popup.module
Javascript popup element processing. Add popup attributes to $element.
date_select_input_value in ./date_api_elements.inc
Helper function for extracting a date value out of user input.

... See full list

File

./date_api.module, line 1734
This module will make the date API available to other modules. Designed to provide a light but flexible assortment of functions and constants, with more functionality in additional files that are not loaded unless other modules specifically include them.

Code

function date_format_order($format) {
  $order = array();
  if (empty($format)) {
    return $order;
  }
  $max = drupal_strlen($format);
  for ($i = 0; $i <= $max; $i++) {
    if (!isset($format[$i])) {
      break;
    }
    $c = $format[$i];
    switch ($c) {
      case 'd':
      case 'j':
        $order[] = 'day';
        break;
      case 'F':
      case 'M':
      case 'm':
      case 'n':
        $order[] = 'month';
        break;
      case 'Y':
      case 'y':
        $order[] = 'year';
        break;
      case 'g':
      case 'G':
      case 'h':
      case 'H':
        $order[] = 'hour';
        break;
      case 'i':
        $order[] = 'minute';
        break;
      case 's':
        $order[] = 'second';
        break;
    }
  }
  return $order;
}