Replace date with Today, Yesterday, "x days ago" [Dates as intervals]
edde42 - February 17, 2009 - 20:37
| Project: | Token |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
Really like this module, it has almost everything I need. One thing that would be real useful for my needs was if it was possible to add a token that will replace the date with "Today", "Yesterday", "x days ago" where x can be both a number or word (three...fifty...) and so on. Or optionally "Today", "Yesterday" and then date when older.

#1
This needs to be in the Token queue, but DO won't let me move it at the moment.
#2
Moving to Token
#3
so is this possible to do ?
#4
Views does it, so it must be.
#5
I added this to template.php (garland theme):
function timeago($nodeorcomment) {
$interval = date('U') - $nodeorcomment;
$hour = 60*60;
$day = 24*$hour;
$time_ago = t("(");
if ($interval < $hour) {
$time_ago .= format_interval($interval, 1) . t(' ago)');
}
elseif ($interval < $day) {
$time_ago .= format_interval($interval, 1) . t(' ago)');
}
elseif ($interval < 2*$day) {
$time_ago .= format_interval($interval, 1) . t(' ago)');
}
else {
$time_ago .= format_interval($interval, 2) . t(' ago)');
}
return $time_ago;
}
function phptemplate_comment_submitted($comment) {
return t('!username !datetime',
array(
'!username' => theme('username', $comment),
'!datetime' => timeago($comment->timestamp)
));
}
and it works like on youtube -> user name (x days ago)
#6
The technique would be similar, but needs to be made as a token (or two).
#7
tommy, i'd tried the code. but it only works for comments and not for nodes' (on it's page or front-page list). any idea for that?
and how can i translate the 'days, weeks, hours, etc.'?