1 date.module | date_format_type_format($format_type, $langcode = NULL) |
Helper function to get the right date format for a format type.
Parameters
string $format_type: Name of the date format, for instance "short", "medium" or "long".
string $langcode: Language code provided, for instance "en".
Return value
string: PHP date format pattern for selected or current language, default pattern if no localized variant exists.
File
- core/
modules/ date/ date.module, line 543 - Defines date/time field types.
Code
function date_format_type_format($format_type, $langcode = NULL) {
$static = &backdrop_static(__FUNCTION__);
if (!isset($static[$langcode][$format_type])) {
$date_format = system_date_format_load($format_type);
// Fallback to (undeletable) medium format if the requested one does not
// exist anymore.
if (!$date_format) {
$date_format = system_date_format_load('medium');
}
// If no langcode has been provided or only LANGUAGE_NONE, use the current
// language to determine the correct localized format.
if (!isset($langcode) || $langcode == LANGUAGE_NONE) {
global $language;
$langcode = $language->langcode;
}
$format = isset($date_format['locales'][$langcode]) ? $date_format['locales'][$langcode] : $date_format['pattern'];
$static[$langcode][$format_type] = $format;
}
return $static[$langcode][$format_type];
}