From 7ea4415616f3b1c0e0f755f03283d1e8f3e17325 Tue, 20 Dec 2011 14:18:47 +0100 From: Bram Goffings Date: Tue, 20 Dec 2011 14:18:32 +0100 Subject: [PATCH] theme_datetime diff --git a/core/includes/common.inc b/core/includes/common.inc index 9da67ac..7e88d78 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1850,7 +1850,9 @@ * 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. @@ -1901,6 +1903,34 @@ case 'long': $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': @@ -6640,6 +6670,9 @@ '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 5304d25..79784eb 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1463,6 +1463,66 @@ */ /** + * 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