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-????].
| Attachment | Size |
|---|---|
| time_tokens.patch | 1.97 KB |

#1
#2
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
Is there something wrong with the curly bracket at line 14?
I get an error trying to apply the patch.
#4
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.
#5
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
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
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
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.
#9
Will ythis be implemented? I really miss theese tokens.
By the way, does this tokens work for comments?
#10
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
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
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
#13
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
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.
#15
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...
#16
Tested and working, both versions.
#17
Patch applied cleanly to token-6.x-1.11. Changing the version of the bug.
#18
Is there any news regarding the adding of this patch to release of the module?
#19
Dump
#20
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...
#21
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
Here's a little module for those who can't wait and don't like to patch. I hope it works.
#23
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
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.
#25
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
Here's a patch for current 6.x-dev including the changes in #20.
#27
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.)