function timeago_format_date in Timeago 6.2
Same name and namespace in other branches
- 7.2 timeago.module \timeago_format_date()
Converts a timestamp into a Timeago date.
Parameters
$timestamp: A UNIX timestamp.
$date: (Optional) A human-readable date (will be displayed if JS is disabled). If not provided, the site default date format is used.
Return value
HTML representing a Timeago-friendly date.
3 calls to timeago_format_date()
- timeago_preprocess_comment in ./
timeago.module - Implementation of hook_preprocess_comment().
- timeago_preprocess_node in ./
timeago.module - Implementation of hook_preprocess_node().
- timeago_token_values in ./
timeago.module - Implementation of hook_token_values().
File
- ./
timeago.module, line 19 - Adds support for the Timeago jQuery library.
Code
function timeago_format_date($timestamp, $date = NULL) {
timeago_add_js();
if (!isset($date)) {
$date = format_date($timestamp);
}
$elem = variable_get('timeago_elem', 'span');
// D6 doesn't support format_date($timestamp, 'custom', 'c') (see
// https://drupal.org/node/494434) so we use gmdate() instead. Note that
// PHP4 doesn't support date('c') either, so we have to manually construct
// the ISO-8601 format. However, PHP4 doesn't have any way to get the
// ISO-8601 year (date('o') in PHP5) so we have to settle for date('Y') which
// returns the "standard" year. date('Y') is sometimes different than
// date('o') on the last week of each standard year.
if (version_compare(phpversion(), '5.0.0', '<')) {
$time = gmdate('Y-m-d\\TH:i:s+00:00', $timestamp);
}
else {
$time = gmdate('c', $timestamp);
}
if ($elem == 'time') {
return '<time class="timeago" datetime="' . $time . '">' . $date . '</time>';
}
else {
return '<' . $elem . ' class="timeago" title="' . $time . '">' . $date . '</' . $elem . '>';
}
return $date;
}