function date_format_type_format in Date 8
Same name and namespace in other branches
- 7.3 date.module \date_format_type_format()
- 7.2 date.module \date_format_type_format()
Helper function to get the right format for a format type. Checks for locale-based format first.
1 call to date_format_type_format()
- date_formatter_format in ./
date.module - Retrieve a date format string from formatter settings.
File
- ./
date.module, line 435 - Defines date/time field types.
Code
function date_format_type_format($format_type, $langcode = NULL) {
$static =& drupal_static(__FUNCTION__);
if (!isset($static[$langcode][$format_type])) {
$format = system_date_format_locale($langcode, $format_type);
// If locale enabled and $format_type inexistent in {date_format_locale}
// we receive (due to inconsistency of core api) an array of all (other)
// formats available for $langcode in locale table.
// However there's no guarantee that the key $format_type exists.
// See http://drupal.org/node/1302358.
if (!is_string($format)) {
// If the configuration page at admin/config/regional/date-time was
// never saved, the default core date format variables
// ('date_format_short', 'date_format_medium', and 'date_format_long')
// will not be stored in the database, so we have to define their
// expected defaults here.
switch ($format_type) {
case 'short':
$default = 'm/d/Y - H:i';
break;
case 'long':
$default = 'l, F j, Y - H:i';
break;
// If it's not one of the core date types and isn't stored in the
// database, we'll fall back on using the same default format as the
// 'medium' type.
case 'medium':
default:
// @todo: If a non-core module provides a date type and does not
// variable_set() a default for it, the default assumed here may
// not be correct (since the default format used by 'medium' may
// not even be one of the allowed formats for the date type in
// question). To fix this properly, we should really call
// system_get_date_formats($format_type) and take the first
// format from that list as the default. However, this function
// is called often (on many different page requests), so calling
// system_get_date_formats() from here would be a performance hit
// since that function writes several records to the database
// during each page request that calls it.
$default = 'D, m/d/Y - H:i';
break;
}
$format = variable_get('date_format_' . $format_type, $default);
}
$static[$langcode][$format_type] = $format;
}
return $static[$langcode][$format_type];
}