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
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

NancyDru - February 19, 2009 - 13:36

This needs to be in the Token queue, but DO won't let me move it at the moment.

#2

NancyDru - February 20, 2009 - 14:17
Title:Replace date with Today, Yesterday, "x days ago"....» Replace date with Today, Yesterday, "x days ago" [Dates as intervals]
Project:Submitted By» Token
Version:6.x-1.2» 6.x-1.x-dev

Moving to Token

#3

tommytom - May 10, 2009 - 19:01

so is this possible to do ?

#4

NancyDru - May 10, 2009 - 21:39

Views does it, so it must be.

#5

tommytom - May 10, 2009 - 23:17

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

NancyDru - May 11, 2009 - 03:44

The technique would be similar, but needs to be made as a token (or two).

#7

sadist - September 18, 2009 - 23:11

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.'?

 
 

Drupal is a registered trademark of Dries Buytaert.