function date_format_options in Date 5.2
Same name and namespace in other branches
- 6.2 date_popup/date_popup.module \date_format_options()
- 6 date/date_admin.inc \date_format_options()
Store personalized format options for each user.
Store to avoid work of re-creating it over and over, personalize for each user to preserve translation.
Return value
array
1 call to date_format_options()
- date_formatter_setup_form in date/
date_admin.inc - A form to create a date formatter option
File
- ./
date_api.module, line 1660 - 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_options() {
global $user;
$cached = cache_get('date_format_options:' . $user->uid);
$options = unserialize($cached->data);
if (empty($options)) {
$formats = array_merge(date_short_formats(), date_medium_formats(), date_long_formats());
$options = array();
$now = date_example_date();
if (!empty($now)) {
foreach ($formats as $format) {
// Create an option that shows date only without time, along with the
// default string which has both date and time.
$no_time = date_limit_format($format, array(
'month',
'day',
'year',
));
$zones = array(
'',
'O',
'P',
'e',
);
foreach ($zones as $zone) {
$time_format = !empty($zone) ? $format . ' ' . $zone : $format;
$options[$no_time] = date_format_date($now, 'custom', $no_time);
$options[$time_format] = date_format_date($now, 'custom', $time_format);
}
}
asort($options);
}
if (!empty($options)) {
cache_set('date_format_options:' . $user->uid, 'cache', serialize($options), CACHE_TEMPORARY);
}
}
return $options;
}