function date_format_order in Date 8
Same name and namespace in other branches
- 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 date_api/date_api.module \date_format_order()
- 7.2 date_api/date_api.module \date_format_order()
Converts a date format to an ordered array of 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: A date format string.
Return value
array An array of ordered elements from the given format string that includes only the date parts that exist in that string.
5 calls to date_format_order()
- datelist_value_callback in date_api/
date_api_elements.inc - Element value callback for datelist element.
- date_combo_validate in ./
date_elements.inc - Validate and update a combo element. Don't try this if there were errors before reaching this point.
- date_views_select_validate in date_views/
date_views.module - Validation hook for exposed filters that use the select widget. This is to ensure the the user completes all parts of the date not just some parts. Only needed for the select widget.
- form_process_datelist in date_api/
date_api_elements.inc - Expands a date element into an array of individual elements (i.e. year, month, day). All form elements are designed to have sane defaults so any or all can be omitted.
- theme_date_all_day in date_all_day/
date_all_day.module - Adjust start/end date format to account for 'all day' .
File
- date_api/
date_api.module, line 67 - 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();
$max = strlen($format);
for ($i = 0; $i < $max; $i++) {
switch ($format[$i]) {
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;
}