Project:Token
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

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.

Comments

#1

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

#2

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

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

#8

Status:active» needs review

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

AttachmentSizeStatusTest resultOperations
375887-token-date-since-D6.patch3.12 KBIgnored: Check issue status.NoneNone

#9

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

#10

Thanks, Dave. I would suggest one change:

  $time = isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : time();

#11

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

AttachmentSizeStatusTest resultOperations
375887-token-date-since-D6.patch10.33 KBIgnored: Check issue status.NoneNone

#12

Re-uploading for the bot

AttachmentSizeStatusTest resultOperations
375887-token-date-since-small.patch10.33 KBIdlePASSED: [[SimpleTest]]: [MySQL] 99 pass(es).View details

#13

Status:needs review» fixed

Committed to CVS.
http://drupal.org/cvs?commit=377474

#14

Status:fixed» closed (fixed)

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