You are here

function date_format_order in Date 5.2

Same name and namespace in other branches
  1. 8 date_api/date_api.module \date_format_order()
  2. 6.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

8 calls to date_format_order()
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.
date_select_process in ./date_api_elements.inc
Flexible date/time drop-down selector.

... See full list

File

./date_api.module, line 1466
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) {
  $max = strlen($format);
  $order = array();
  for ($i = 0; $i <= $max; $i++) {
    $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;
}