Update Date code in Token module for API changes in Date 2.x
lsabug - January 5, 2008 - 16:13
| Project: | Token |
| Version: | 5.x-1.x-dev |
| Component: | Documentation |
| Category: | task |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | closed |
Description
in /home/domain/public_html/modules/token/token_cck.inc on line 258.
I just updated my date module to head and created a birthdate select field . I entered -100:-18 and then -100:+0 in the Years Back and Forward section.
When I tried to submit a cck form with this I received the previous error of undefined function: date_fuzzy_stamp. I'm not sure what this error means, I do have token module installed. Should I go back and install the dec. 28 version instead?
Thanks.

#1
I've decided to go back to dec. 28 version. Thanks.
#2
I get a fatal error of 'Call to undefined function date_show_date() in /opt/www/drupal-5.2.int.thatsbj.com/sites/all/modules/token/token_cck.inc on line 264'
pretty much the same error as the above post. I presume that there are new replacement functions for date_show_date (and date_fuzzy_stamp) that could be used to patch up token_cck? I'd like to continue testing the new Date module.
#3
I didn't realize the token module had date code in it. The Date API has changed so that will need to be fixed. When I get a chance I can try to figure out what patch is needed for the token module, but I can't do it right now.
If you're interested, maybe you can figure out a patch?
#4
Well token_cck calls both date_make_date and date_show_date. The first function from the date module still exists in HEAD but the second function date_show_date does not. Also it seems that the parameters for date_make_date and date_format_date have changed in HEAD.
The code block in token_cck contains the following where $item would be a date CCK field:
$item['value'] = trim($item['value']);
$item_format = (is_numeric($item['value']) ? DATE_UNIX : DATE_ISO);
$date = date_make_date($item['value'], 'none', 'local', $item_format);
$tokens['value'] = $item['value'];
$tokens['view'] = $item['view'];
$tokens['timestamp'] = $date->local->timestamp;
$tokens['yyyy'] = date_show_date($date, 'Y');
$tokens['yy'] = date_show_date($date, 'y');
$tokens['month'] = date_show_date($date, 'F');
$tokens['mon'] = date_show_date($date, 'M');
$tokens['mm'] = date_show_date($date, 'm');
$tokens['m'] = date_show_date($date, 'n');
$tokens['ww'] = date_show_date($date, 'W');
$tokens['date'] = date_show_date($date, 'N');
$tokens['day'] = date_show_date($date, 'l');
$tokens['ddd'] = date_show_date($date, 'D');
$tokens['dd'] = date_show_date($date, 'd');
$tokens['d'] = date_show_date($date, 'j');
So with the new date API what would be the equivalent call for date_make_date to create the date object? I figure that's probably the more important change. Then replacing date_show_date would presumably be accomplished via another new or renamed date API function.
Is there an API changelist somewhere that would detail how to use the new API to port old code?
#5
Since the code needed is different depending on what version of the Date module you're using, what we probably ought to do is move that code into the Date module so it will have the code that matches the version.
Basically the new code would be (doing this from memory, so hope I have it right):
$item['value'] = trim($item['value']);
$item_format = (is_numeric($item['value']) ? DATE_UNIX : DATE_ISO);
$timezone = $item['timezone'] ? $item['timezone'] : date_default_timezone_name();
$date = date_make_date($item['value'], $timezone, $item_format);
$tokens['value'] = $item['value'];
$tokens['view'] = $item['view'];
$tokens['timestamp'] = date_format_date($date,'custom', 'U');
$tokens['yyyy'] = date_format_date($date, 'custom', 'Y');
$tokens['yy'] = date_format_date($date, 'custom', 'y');
$tokens['month'] = date_format_date($date, 'custom', 'F');
$tokens['mon'] = date_format_date($date, 'custom', 'M');
$tokens['mm'] = date_format_date($date, 'custom', 'm');
$tokens['m'] = date_format_date($date, 'custom', 'n');
$tokens['ww'] = date_format_date($date, 'custom', 'W');
$tokens['date'] = date_format_date($date, 'custom', 'N');
$tokens['day'] = date_format_date($date, 'custom', 'l');
$tokens['ddd'] = date_format_date($date, 'custom', 'D');
$tokens['dd'] = date_format_date($date, 'custom', 'd');
$tokens['d'] = date_format_date($date, 'custom', 'j');
#6
Renaming this issue so it's easier to find. The best solution is probably going to be moving the token module code from Token to Date, then we can have the right code for the right date version.
Anyone up for making a patch for both Date and Token to get that done?
#7
If you have the token module installed, very bad things happen when you try to do an update (as in site update) of date
#8
i'm getting a similar error with Token and Date as soon as i preview or submit any node:
setting this to critical as basically is impossible to insert date content in a site. thanks
#9
ok, updated token_cck.inc with new values from KarenS at #5, but seems there are other rows to update right below those ones:
$item['value2'] = trim($item['value2']);
$item_format = (is_numeric($item['value2']) ? DATE_UNIX : DATE_ISO);
$date = date_make_date($item['value2'], 'none', 'local', $item_format);
$tokens['to-value'] = $item['value2'];
$tokens['to-view'] = $item['view2'];
$tokens['to-timestamp'] = $date->local->timestamp;
$tokens['to-yyyy'] = date_show_date($date, 'Y');
$tokens['to-yy'] = date_show_date($date, 'y');
$tokens['to-month'] = date_show_date($date, 'F');
$tokens['to-mon'] = date_show_date($date, 'M');
$tokens['to-mm'] = date_show_date($date, 'm');
$tokens['to-m'] = date_show_date($date, 'n');
$tokens['to-ww'] = date_show_date($date, 'W');
$tokens['to-date'] = date_show_date($date, 'N');
$tokens['to-day'] = date_show_date($date, 'l');
$tokens['to-ddd'] = date_show_date($date, 'D');
$tokens['to-dd'] = date_show_date($date, 'd');
$tokens['to-d'] = date_show_date($date, 'j');
tryed to have a look at date.module, but things looked bit harsh for a non-programmer.. :P
PS: also seems that token.inc is still looking for /date/date.inc (line 252) so it throws some other 'include' errors.
#10
This is critical for people trying to get this module to work. Creating patches to get this to work is all fine but can someone save us all a bunch of time and at least tell us what version of the date module is compatible with what version of the token module?
#11
The version 2 branch of Date is incompatible with token.
#12
subscribing
#13
This worked for me.
Search and replacing date_show_date() with date_format_date() and removing with the date module enabled, of course.
include_once(drupal_get_path('module', 'date') .'/date.inc');Shouldn't the token module require the date API module through a "dependencies" entry in token.info and not include it in this way?
Hope this is of help.
#14
Here is my code for token_cck.inc lines 252-303.
This seems to be working for me. It's a little bit of a combination of all the comments above. I don't get any error messages on View, Edit, or Submit.
function date_token_values($type, $object = NULL, $options = array()) {
if ($type == 'field') {
$item = $object[0];
$item['value'] = trim($item['value']);
$item_format = (is_numeric($item['value']) ? DATE_UNIX : DATE_ISO);
$timezone = $item['timezone'] ? $item['timezone'] : date_default_timezone_name();
$date = date_make_date($item['value'], $timezone, $item_format);
$tokens['value'] = $item['value'];
$tokens['view'] = $item['view'];
$tokens['timestamp'] = $date->local->timestamp;
$tokens['yyyy'] = date_format_date($date, 'custom', 'Y');
$tokens['yy'] = date_format_date($date, 'custom', 'y');
$tokens['month'] = date_format_date($date, 'custom', 'F');
$tokens['mon'] = date_format_date($date, 'custom', 'M');
$tokens['mm'] = date_format_date($date, 'custom', 'm');
$tokens['m'] = date_format_date($date, 'custom', 'n');
$tokens['ww'] = date_format_date($date, 'custom', 'W');
$tokens['date'] = date_format_date($date, 'custom', 'N');
$tokens['day'] = date_format_date($date, 'custom', 'l');
$tokens['ddd'] = date_format_date($date, 'custom', 'D');
$tokens['dd'] = date_format_date($date, 'custom', 'd');
$tokens['d'] = date_format_date($date, 'custom', 'j');
if (!empty($item['value2'])) {
$item['value2'] = trim($item['value2']);
$item_format = (is_numeric($item['value2']) ? DATE_UNIX : DATE_ISO);
$timezone = $item['timezone'] ? $item['timezone'] : date_default_timezone_name();
$date = date_make_date($item['value2'], $timezone, $item_format);
$tokens['to-value'] = $item['value2'];
$tokens['to-view'] = $item['view2'];
$tokens['to-timestamp'] = $date->local->timestamp;
$tokens['to-yyyy'] = date_format_date($date, 'custom', 'Y');
$tokens['to-yy'] = date_format_date($date, 'custom', 'y');
$tokens['to-month'] = date_format_date($date, 'custom', 'F');
$tokens['to-mon'] = date_format_date($date, 'custom', 'M');
$tokens['to-mm'] = date_format_date($date, 'custom', 'm');
$tokens['to-m'] = date_format_date($date, 'custom', 'n');
$tokens['to-ww'] = date_format_date($date, 'custom', 'W');
$tokens['to-date'] = date_format_date($date, 'custom', 'N');
$tokens['to-day'] = date_format_date($date, 'custom', 'l');
$tokens['to-ddd'] = date_format_date($date, 'custom', 'D');
$tokens['to-dd'] = date_format_date($date, 'custom', 'd');
$tokens['to-d'] = date_format_date($date, 'custom', 'j');
}
return $tokens;
}
}
Hopefully someone can create a patch of this. I really need to learn how to do that! :-)
Artis
#15
Here the patch based on artis' code
#16
Note that this is a patch for the Token module, not the Date module. It doesn't do any good to post it here, it needs to be posted in the Token module issue queue, so moving it there.
#17
Changes Title to be more descriptive. Changing version to the version code was applied to.
In other words don't apply this patch unless you are using Date Module 5.x-2.x
#18
@karens - I agree that in order for this to work properly regardless of the date module version that people are using the token code needs to be moved to date module.
For anyone who wants to make a full patch:
1) It should move this code _out_ of token module and into date module
2) It will require 2 patches for date module - 1 for the old style of date formatters and 1 for the new
3) It will remove the token code related to date module
I'm tempted to just remove this from token and let you folks handle it in Date separately - thoughts? At least that way we wouldn't have problems with non existent functions...
#19
I was waiting to hear if you preferred a patch in Token or moving it to Date. I think I have enough info now to figure out the right patches to make in Date if you tell me when you're making the change in the Token module so we can do it at the same time.
#20
I've got a patch here which I have applied to the 5.x branch and the 6.x branch. It will check to see if the date_token_list function already exists before declaring it which will help during the migration period. Sound good?
Reassigning to date queue for the remainder of the work. Once you've fixed this there and done an "official release" so that we think people are upgraded to the version where date contains the tokens then we can _really_ remove it and do a new release of token.
#21
We may still end up with a race condition, so I wrapped the new functions in the Date module in a check for function_exists(), too. Committed to 5.1, 5.2, and 6.x.
#22
Agreed - thanks for fixing this.
#23
Automatically closed -- issue fixed for two weeks with no activity.
#24
So can someone clarify which versions of the modules work together and which do not?
I' a bit confused. Thank you!
#25
Ups, Title should stay.
#26
I can´t say which versions of date that you will need. I believe you will need a 5.x-1.x-dev version of token, though. When it does get rolled into an official release it will be 5.x-1.11 of token.
#27
You need the latest version of Token that has the fixes to the date code, see #26.
#28
Marking this active again to suggest getting this change into an official release. I keep getting issues about this (and I see more of them in the Token queue) so it's probably time to get this into an official release.
#29
Oops, I re-activate a Date issue and I need to get this into the Token module.
#30
I just create a 5.x-1.11 release so this shouldn't be a problem any more.
Thanks, KarenS.
#31
Automatically closed -- issue fixed for two weeks with no activity.