function webform_date_format in Webform 7.4
Same name and namespace in other branches
- 5.2 components/date.inc \webform_date_format()
- 6.3 webform.module \webform_date_format()
- 6.2 components/date.inc \webform_date_format()
- 7.3 webform.module \webform_date_format()
Get a date format according to the site settings.
Parameters
$type: A choice of 'short', 'medium', 'long' , or other user-defined date formats. Use NULL for the webform-specific date format choosen in the webform settings.
array $exclude: An array containing 'day', 'month', and/or 'year' if they should be removed from the format.
Return value
string A date/time format string.
10 calls to webform_date_format()
- theme_webform_display_date in components/
date.inc - Format the text output for this component.
- theme_webform_results_download_range in includes/
webform.report.inc - Theme the output of the export range fieldset.
- webform_admin_settings in includes/
webform.admin.inc - Menu callback for admin/config/content/webform.
- webform_conditional_form_date in includes/
webform.conditionals.inc - Form callback for date conditional fields.
- webform_download_sids_query in includes/
webform.report.inc - Given a set of range options, return an unexecuted select query.
File
- ./
webform.module, line 5186 - This module provides a simple way to create forms and questionnaires.
Code
function webform_date_format($type = NULL, array $exclude = array()) {
static $formats = array();
$id = $type . ':' . implode('', $exclude);
if (!isset($formats[$id])) {
$type_name = $type ? $type : webform_variable_get('webform_date_type');
// Format date according to site's given format.
$format = variable_get('date_format_' . $type_name, 'D, m/d/Y');
// Date/Time formatting characters
// WHAT REQUIRED (at least 1) OPTIONAL (allowed but insufficient)
// -------------------------------------------------------------------------
// Day-of-week DlNw
// Day dj Stz
// Month FmMn
// Year oYy L
//
// NOT ALLOWED
// -------------------------------------------------------------------------
// Time aABgGhHisueIOPTZ
// Special /.,-: <space>
//
// Strip Time and Special characters from the beginning and end of format.
$date_format = trim($format, 'aABgGhHisueIOPTZ/.,-: ');
// Ensure that a day, month, and year value are present. Use a default
// format if all the values are not found. This regular expression uses
// (?= ), the positive lookahead assertion. It asserts that there are some
// optional characters (.*) followed by one of the day, month, or year
// characters. Because it is an assertion, it doesn't consume the
// characters, so the day, month, and year can be in any order.
if (!preg_match('/(?=.*[dj])(?=.*[FmMn])(?=.*[oYy])/', $date_format)) {
$date_format = 'm/d/Y';
}
// Remove any excluded portions.
$strip = array(
'day' => 'DlNwdjStz',
'month' => 'FmMn',
'year' => 'oYyL',
);
foreach ($exclude as $field) {
// Strip the format and any trailing /.,-: or space.
$date_format = preg_replace('#[' . $strip[$field] . ']+[/\\.,\\-: ]*#', '', $date_format);
$date_format = trim($date_format, '/.,-: ');
}
$formats[$id] = $date_format;
}
return $formats[$id];
}