function date_format_options in Date 6
Same name and namespace in other branches
- 5.2 date_api.module \date_format_options()
- 6.2 date_popup/date_popup.module \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/
date_admin.inc, line 457 - Date administration code. Moved to separate file since there is a lot of code here that is not needed often.
Code
function date_format_options() {
global $user;
$options = array();
$cached = cache_get('date_format_options:' . $user->uid);
$options = isset($cached->data) ? $cached->data : array();
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, $options, 'cache', CACHE_TEMPORARY);
}
}
return $options;
}