I was adding tokens for the Web Links module, which has several dates. I borrowed on token_node.inc for this, but decided it would be even nicer if there was a function within Token to do this. So here's a patch (5.x and 6.x versions).

Comments

nancydru’s picture

StatusFileSize
new1.53 KB
new1.53 KB

Let's add "-since".

nancydru’s picture

StatusFileSize
new1.66 KB

It would be simple enough to use this function to provide #179297: Tokens for minutes and seconds.

lomz’s picture

the last one contains all?

nancydru’s picture

IIRC, yes. If it works well for you please mark this issue RTBC.

lomz’s picture

cl-k@web3:~/web/modules/token$ patch < token6_1.patch 
(Stripping trailing CRs from patch.)
patching file token.module
patch: **** malformed patch at line 49:  
nancydru’s picture

This must be a Windows gotcha! It applies for me. Can you apply it manually?

lomz’s picture

No, I think it is Ubuntu.

I'll try to add it manully

nancydru’s picture

StatusFileSize
new1.62 KB

I created this version with CVS.

lomz’s picture

works

nancydru’s picture

I won't mark my own patch as RTBC.

lomz’s picture

Oh, i meant the patch, I review it tommorow

lomz’s picture

I dont the the seconds, minutes and hours to show up wgen trying to set the submitted by text

christefano’s picture

I don't think this should be in token.module. The place for node tokens is in token_node.inc, which is what #323441 add timestamp tokens (g, G, h, H, i, s, U) for hours, minutes and seconds targets.

nancydru’s picture

@christefano: Take a look at the patch. This does not create tokens itself. It is a function to format dates and times to be used for creating date and time tokens. It is generic, and the only place it should be is in the base module.

lomz’s picture

But since I need tokens for hours minutes and seconds they need t be created dont they?

nancydru’s picture

Yes, there should be a patch for token_node (and the others) that uses the function from the patch in this issue.

lomz’s picture

Is that hard to make?

nancydru’s picture

token_date_values($comment->timestamp, 'comment');

lomz’s picture

But how to transfer that into token_comments?

donquixote’s picture

what's the status here?

donquixote’s picture

@lomz(#19):
"But how to transfer that into token_comments?"

<?php
$values['comment-yyyy']            = date('Y', $comment->timestamp);
$values['comment-yy']              = date('y', $comment->timestamp);
$values['comment-month']           = date('F', $comment->timestamp);
$values['comment-mon']             = date('M', $comment->timestamp);
$values['comment-mm']              = date('m', $comment->timestamp);
$values['comment-m']               = date('n', $comment->timestamp);
$values['comment-ww']              = date('W', $comment->timestamp);
$values['comment-date']            = date('N', $comment->timestamp);
$values['comment-day']             = date('l', $comment->timestamp);
$values['comment-ddd']             = date('D', $comment->timestamp);
$values['comment-dd']              = date('d', $comment->timestamp);
$values['comment-d']               = date('j', $comment->timestamp);
?>

becomes

<?php
$values += token_date_values($comment->timestamp, 'comment');
?>

(array keys are all strings, so this array arithmetics should work)

donquixote’s picture

@NancyDru:
I don't see hours and minutes and seconds in your patch..

christefano’s picture

I don't see hours and minutes and seconds in your patch..

Those are proposed by another patch (#323441: add timestamp tokens (g, G, h, H, i, s, U) for hours, minutes and seconds). Perhaps the two different issues should be merged.

nancydru’s picture

Well, the maintainers are too busy putting this into core for D7 to do anything here.

summit’s picture

Hi, issue with time function on token_node.inc, line 48, latest version.

date() [<a href='function.date'>function.date</a>]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CET/1.0/no DST' instead

Greetings, Martijn

dave reid’s picture

Assigned: nancydru » dave reid
StatusFileSize
new12.62 KB

Here's the patch I had made up before I even saw this issue to help reduce even more code.

christefano’s picture

Status: Needs review » Reviewed & tested by the community

Patch applies with slight offset with token_node.inc. Looks good to me.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, token6.patch, failed testing.

tobiasb’s picture

Status: Needs work » Needs review
StatusFileSize
new12.72 KB
dave reid’s picture

Status: Needs review » Fixed

Committed to CVS. Thanks everyone!
http://drupal.org/cvs?commit=340220

Status: Fixed » Closed (fixed)

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