diff --git a/core/includes/common.inc b/core/includes/common.inc index 99fcdba..c448bb8 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1850,7 +1850,9 @@ function format_interval($timestamp, $granularity = 2, $langcode = NULL) { * A UNIX timestamp to format. * @param $type * (optional) The format to use, one of: - * - 'short', 'medium', or 'long' (the corresponding built-in date formats). + * - One of the built-in formats: 'short', 'medium', 'long', 'html_datetime', + * 'html_time', 'html_date', 'html_yearless_date', 'html_week', + * 'html_month', 'html_year'. * - The name of a date type defined by a module in hook_date_format_types(), * if it's been assigned a format. * - The machine name of an administrator-defined date format. @@ -1903,6 +1905,34 @@ function format_date($timestamp, $type = 'medium', $format = '', $timezone = NUL $format = variable_get('date_format_long', 'l, F j, Y - H:i'); break; + case 'html_datetime': + $format = variable_get('date_format_html_datetime', 'Y-m-d\TH:i:sO'); + break; + + case 'html_time': + $format = variable_get('date_format_html_time', 'H:i:s'); + break; + + case 'html_date': + $format = variable_get('date_format_html_date', 'Y-m-d'); + break; + + case 'html_yearless_date': + $format = variable_get('date_format_html_yearless_date', 'm-d'); + break; + + case 'html_week': + $format = variable_get('date_format_html_week', 'Y-\WW'); + break; + + case 'html_month': + $format = variable_get('date_format_html_month', 'Y-m'); + break; + + case 'html_year': + $format = variable_get('date_format_html_year', 'Y'); + break; + case 'custom': // No change to format. break; @@ -6640,6 +6670,9 @@ function drupal_common_theme() { 'render element' => 'elements', 'template' => 'region', ), + 'datetime' => array( + 'variables' => array('timestamp' => NULL, 'text' => NULL, 'options' => array('attributes' => array(), 'html' => FALSE)), + ), 'status_messages' => array( 'variables' => array('display' => NULL), ), diff --git a/core/includes/theme.inc b/core/includes/theme.inc index e6c0725..85f2f15 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1463,6 +1463,66 @@ function theme_disable($theme_list) { */ /** + * Preprocess variables for theme_datetime(). + */ +function template_preprocess_datetime(&$variables) { + // Use the datetime attribute if provided. + if (!isset($variables['options']['attributes']['datetime'])) { + // If the datetime attribute was not provided, attempt to use the timestamp + // value as the datetime attribute. + if (isset($variables['timestamp'])) { + // Format the datetime attribute. + // See http://www.w3.org/TR/html5-author/the-time-element.html#attr-time-datetime + $variables['options']['attributes']['datetime'] = format_date($variables['timestamp'], 'html_datetime', '', 'UTC'); + // If no text for the