function date_format_order in Date 7
Same name and namespace in other branches
- 8 date_api/date_api.module \date_format_order()
- 5.2 date_api.module \date_format_order()
- 6.2 date_api.module \date_format_order()
- 6 date_api.module \date_format_order()
- 7.3 date_api/date_api.module \date_format_order()
- 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
13 calls to date_format_order()
- date_default_date in date_api/
date_api_elements.inc - Create a date object from a datetime string value.
- date_parts_element in date_api/
date_api_elements.inc - Create form elements for one or more date parts.
- date_popup_date_granularity in date_popup/
date_popup.module - date_popup_element_value_callback in date_popup/
date_popup.module - Element value callback for date_popup element.
- date_popup_input_date in date_popup/
date_popup.module - Helper function for extracting a date value out of user input.
File
- date_api/
date_api.module, line 1674 - 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 = 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;
}