add timestamp tokens (g, G, h, H, i, s, U) for hours, minutes and seconds

christefano - October 19, 2008 - 22:21
Project:Token
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review
Description

This patch adds support for 12- and 24-hour node creation times. It also makes these new tokens available for modication times when using [mod-????].

AttachmentSize
time_tokens.patch1.97 KB

#1

christefano - October 19, 2008 - 22:48
Title:add timestamp tokens (e.g. g, G, h, H)» add timestamp tokens (g, G, h, H, i, s) for hours, minutes and seconds
AttachmentSize
323441_time_tokens.patch 2.35 KB

#2

agharbeia - October 20, 2008 - 11:43

Very much needed for creating unique hackable URLs, or more precisely for creating more-likely-to-be unique URLs, which almost always works for a single user's site (i.e blog).

I hope this finds it way to the next release.

I searched and found this on the exact same day it was released!! What are the odds!

#3

agharbeia - October 20, 2008 - 12:37

Is there something wrong with the curly bracket at line 14?

I get an error trying to apply the patch.

#4

agharbeia - October 20, 2008 - 14:34

The patch in the parent is no good:

First: It has no code for the i and s specifiers (minutes and econds)

Second: the code has the date() function formatter "H" for all the different hour formats advertised

See the atached patch instead.

On a side note, adding Swatch Internet time would also be nice for the purpose of creating URLs.

AttachmentSize
323441_token_node.inc_.patch 2.25 KB

#5

christefano - October 20, 2008 - 17:32

Thanks for fixing those problems, agharbeia! I was in a big hurry when patching Token for our launch a few hours ago and ended up submitting a broken patch. #4 is perfect. I'd mark it RTBC but I'm not sure what you mean about "It has no code for the i and s specifiers (minutes and econds)." It's working for me.

Does anyone still use Swatch Internet Time?

#6

agharbeia - October 20, 2008 - 20:45

Well, thanks to you, christefano, for giving me the lead. It's the first time I modified Drupal code and submitted a patch.

Regarding seconds and minutes, do you mean that you could see advertised tokens for these components in the original patch? I couldn't.

Internet time is cool if it's going to be used as part of a URL. Just as a pseudo-unique identifier to follow the date components where the the HHMMSS would have been placed, which is how I currently create nodes' paths.

#7

christefano - October 20, 2008 - 21:10

Support for seconds and minutes was added in #1 (and are in your improved version in #4) but were missing from the original post. Are they not appearing in your token lists (like the replacement list in Pathauto)?

I'm not sure how useful Swatch Internet Time would be as an identifier since each "beat" is about 1½ minutes. It's okay with me if you want to add it in new patch, though. Microseconds would be more useful for that, I think, but support for it is only in newer versions of PHP 5.

#8

christefano - November 2, 2008 - 22:23
Title:add timestamp tokens (g, G, h, H, i, s) for hours, minutes and seconds» add timestamp tokens (g, G, h, H, i, s, U) for hours, minutes and seconds

The last patch didn't apply cleanly and had tabs instead of spaces. While rerolling it, I added support for Epoch (seconds since January 1, 1970) and rolled a patch for Token 6.x-1.x-dev.

AttachmentSize
323441_timestamp_tokens_5.x.patch 2.58 KB
323441_timestamp_tokens_6.x.patch 2.57 KB

#9

lomz - November 15, 2008 - 14:57

Will ythis be implemented? I really miss theese tokens.

By the way, does this tokens work for comments?

#10

christefano - November 15, 2008 - 22:13

No, this patch is for token_node.inc but adding support in token_comment.inc is a pretty much a copy-and-paste job. Would you like to submit a patch?

#11

lomz - November 16, 2008 - 05:56

Shall look into it.

But it seems to be an error in the patch

+        $values['s']              = date('s', $date);
+        $values['U']              = date('s', $date);

And
+        $values['mod-s']          = date('s', $date);
+        $values['mod-U']          = date('s', $date);

#12

lomz - November 16, 2008 - 06:48

Created a patch, but it fails, could yyou help me figure out whats wrong?
I used diff -up as spesified in http://drupal.org/patch/create

I also added the entire new token_comment.inc

AttachmentSize
323441_timestamp_token_comment_6.x.patch 2.12 KB
token_comment.inc_.txt 5.76 KB

#13

lomz - November 16, 2008 - 06:56

Also adding my own token_comment.inc, with both the last changes I mentioned and #325227: Provide e-mail and commenter homepage tokens for comments.

#14

lomz - November 23, 2008 - 09:53

Attaching patch without errors.
This patch is basicly the same as in #12.
Adds g, G, h, H, i, s, U for comments, has been tested for a week now.

AttachmentSize
6.patch 1.75 KB

#15

lomz - November 23, 2008 - 10:07

Added the original patch, corrected for comment 11:
http://drupal.org/node/323441#comment-1109915

I hope this can be added to -dev, so I dont need to remember to patch the file for every new update...

AttachmentSize
323441_timestamp_tokens_5.x.patch 2.58 KB
323441_timestamp_tokens_6.x.patch 2.57 KB

#16

pkej - December 23, 2008 - 12:05
Status:needs review» reviewed & tested by the community

Tested and working, both versions.

#17

somnoliento - February 27, 2009 - 19:33
Version:5.x-1.x-dev» 6.x-1.x-dev

Patch applied cleanly to token-6.x-1.11. Changing the version of the bug.

#18

lomz - April 15, 2009 - 19:43

Is there any news regarding the adding of this patch to release of the module?

#19

lomz - April 26, 2009 - 12:45

Dump

#20

lomz - April 27, 2009 - 17:59

Here is my new editions of token_node and token_comment that reflects the patch for 6.x that is above.
I did not care for making a patch, but somebody can volunteer...

AttachmentSize
token_comment.inc_.txt 5.76 KB
token_node.inc_.txt 15.6 KB

#21

donquixote - July 29, 2009 - 10:18

subscribe.

Also have a look at this one:
http://drupal.org/node/307520

For me the hours and minutes are more important, the refactoring can happen in a later stage.

#22

donquixote - July 29, 2009 - 13:25

Here's a little module for those who can't wait and don't like to patch. I hope it works.

AttachmentSize
token_time.zip 7.07 KB

#23

agharbeia - August 19, 2009 - 02:42

I just noticed that the date & time tokens are replaced by dates in the time zone of the server (in my case seemingly US/Pacific), even though /admin/settings/date-time is set to another time zone (in my case Africa/Cairo), and even after I added "date.timezone =Africa/Cairo" in php.ini

The displayed node creation time on the node itself is correct, however. Only those returned by the tokens are shifted.

For example see http://ahmad.gharbeia.org/2009/08/18/183437, which token-derived URL alias has a time different than the real creation time, which is displayed on the node itself as 2009/08/19 04:34.

#24

lesergi - October 8, 2009 - 16:52

I think this is a critical error...

Let's see... Following great work done by donquixote, I fixed a little this module.

Now it's using format_date instead date, and comments tokens has been fixed.

Here it's.

AttachmentSize
token_time.zip 7.23 KB

#25

the.alphy - October 27, 2009 - 21:22

Does anyone know the status of this and when it might be rolled into an official release? I agree with the lesergi that this is a critical fix. :)

#26

jeffschuler - November 5, 2009 - 07:49
Status:reviewed & tested by the community» needs review

Here's a patch for current 6.x-dev including the changes in #20.

AttachmentSize
323441_timestamp_tokens_6.x_1.patch 5.23 KB

#27

jeffschuler - November 5, 2009 - 08:15

I added AM/PM (and lowercase am/pm,) since a 12-hour clock is useless without it.

(...The list of date/time tokens could just keep growing. Could just have a [node:date-custom-????] token and allow for a php date format string...?)

I also changed the description for g, G, h, and H to "Node creation hour" instead of "Node creation time" to be consistent with the other choices. (Changed it for comment, too.)

AttachmentSize
323441_timestamp_tokens_6.x_2.patch 5.95 KB
 
 

Drupal is a registered trademark of Dries Buytaert.