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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

NancyDru’s picture

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

NancyDru’s picture

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

tommytom’s picture

so is this possible to do ?

NancyDru’s picture

Views does it, so it must be.

tommytom’s picture

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)

NancyDru’s picture

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

sadist’s picture

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

Dave Reid’s picture

Status: Active » Needs review
FileSize
3.12 KB

Patch that adds a 'since' date token. For nodes it's [since] and [mod-since], for comments its [comment-since], etc.

Dave Reid’s picture

Title: Replace date with Today, Yesterday, "x days ago" [Dates as intervals] » Add a 'since' date token
NancyDru’s picture

Thanks, Dave. I would suggest one change:

  $time = isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : time();
Dave Reid’s picture

Revised patch that adds a '-small' date prefix, uses standard date tokens for user login and creation (while still supporting the legacy tokens).

Dave Reid’s picture

Re-uploading for the bot

Dave Reid’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.