Description:

Date [node:field-name-here:custom:?] tokens are not displaying correctly when used for automatic node titles. The titles using "Date tokens" are displayed -1 year from whatever date you selected on the node. So if you select 2011 in the node, and then save. You will see the token generated 2010 for the node title.

Installed Modules:

auto_nodetitle-dev-7.x-1.0
date-7.x-2.0-alpha3

Recreate Issue:

1. Create a new content type.
2. Add a date field to that content type. (Year, field_year, Date, Select List)
3. Configure automatic title generation for that content type. Check "Automatically generate the title and hide the title field". Use [node:field-year:custom:Y] as your "Pattern for the title".
4. Create a node for that content type. Select a "Year" value and save.
5. The date thats specified in the node is -1 year for the title. So if you selected 2011 it would show 2010 instead.

Files: 
CommentFileSizeAuthor
#21 1197278.patch1.17 KBcasey

Comments

How did you get it to even create a token for the new field?

I don't know if this should go in a new issue or not... I'm having issues with date tokens but not the same as yours.. If I put in just Y like you did, it correctly puts in 2011. I'm using a date field with a pop up calendar that has year, month, and day. So it seems to work with that setup. But trying to put F, Y or F Y or even 'F, Y' in there results in the token not being recognized.

Michelle

Oh, duh, it just occurred to me that the ? might only be meant to replace one bit of the date. I put in two tokens, one for month, one for year and that works. So my problem might be by design...

At any rate, I am getting the correct date out of it so it may be particular to the widget you're using?

Michelle

@NancyDru - I did have a problem with the token not getting populated for the new field as well. After clearing my drupal cache, the token field populated in the token replacements.

@Michelle - It looks like we are having two different issues. I found out that the custom date token doesn't like spaces when using custom PHP date replacements. This seems to work though for me [node:field-YOUR_FIELD_NAME:custom:F,Y] I think your problem is related to the space issue, correct? When I use this custom date token [node:field-YOUR_FIELD_NAME:custom:F,Y] everything shows up correctly in the node title that's been created. It's only when I use [node:field-YOUR_FIELD_NAME:custom:Y] the year is -1 year from the year I selected.

EDIT: It only seem like this is an issue if the date "Granularity" option field is only set to "year".

Here is a screencast of this issue:
http://dl.dropbox.com/u/1211031/AutoNodeTitle-Date-Issue-1197278.mov

Nope, I am not getting fields to show up like you show in your screencast, but then mine are not dates, they are text. Yes, I have cleared the cache about a billion times working on a Calendar issue.

Yeah, it's probably the space that's doing it.

Same here for me having to clear the cache before new field tokens will show up.

Michelle

As a matter of fact, I looked at the content type for one that has a date field and no tokens there either.

You do have the Token module installed, right? That may sound silly but that tripped me up at first because, for some reason, I thought Token was part of core in D7.

Michelle

Yes, I have Token and Token Fields.

I am having an issue as well, I am using a content token and it's generating everything a day behind the date I input.

My node title looks like this: [node:field-news-category] [node:content-type] [node:field-news-date:medium]

If I input my date as September 20 2010, the title generated says "September 19 2010".

....I can't see that it's a time zone issue either, i'm not using hour or minute increments.

Becky

I am having a slightly different problem. I am trying to use a custom date token - exactly like at screencast #14.

When I select node tokens I find that the date token are not present. Just Date Changed and Date Created.

It's quite important to me, if anybody can put me right.

=====
EDIT

Have looked in to this further, the problem appears to be due to an issue in the token module together with a knock-on issue in the date module.
http://drupal.org/node/1103032#comment-4977086

Has there been any updates on this issue? Date tokens still appear to be "one off" when used in the module, be it year, date, etc.

I am having the exact same issue. the date displayed in the auto node title via tokens is one day before the date actual saved to the node.

Anyone have an answer?

My php god discovered the source of the issue. The date is always reading from the "long" date type. Whatever format you put into the Long will show up in the node title. It's a frustrating workaround, but you can at least have control over the date in your title.

Go to "admin/config/regional/date-time" and create the format to select in the Long format.

HTH,
Stephen

Same issue here. Anyone have a workaround/patch for this?

Same issue for me.

Just to clarify, I have a node with a "publication date" field. That is a date field with year, month, day granularity.

Tokens are used to construct the title for that node (with auto node title module), path (using pathauto), and breadcrumb (using custom breadcrumbs). The date is also displayed when that node is viewed.

If client selects a date, let's say 01/23/12, for that field, the date is displayed properly in the node's field and the path. It is, however, showing one day too early (1/22/12) for the node title (and, of course, the breadcrumb as it displays the node title).

Screenshot showing this behavior: https://skitch.com/scottrouse/8nt7y/autonodetitle-oboe

This is absolutely a timezone issue. If your date field is only using the year granularity, the raw data of the date is set for Jan 1 of that year at 00:00:00. So when timezone differences are applied, you end up back on Dec 31 of the year before.

In my case I'm using day granularity and when I test with 1998-01-01 (which becomes 1998-01-01 00:00:00), I end up with a title of "Wed, 12/31/1997 - 19:00" when I use the Entity Token value of [node:field-date-event:medium] for my title.

When I put that same token value in the body of my node, it correctly outputs: "Thu, 01/01/1998 - 00:00" (using the Token Filter module). My timezone is for NYC which is GMT -5.

So I haven't had time yet to figure out what auto_nodetitle is doing differently than token_filter, but if anyone is researching this, I would definitely look to timezone information not being set correctly somewhere in the call chain.

My solution is to set the site's default time zone (admin/config/regional/settings) to the UTC time zone and disable the option for users to set their own time zone. UTC just so happens to be the time zone of my production server anyway for this site.

I'm experiencing this same issue, but I noticed an additional detail. When saving the node initially, the date is generated incorrectly. However, if you go to the 'find content' screen and use the 'update automatic node titles' action, the date will be corrected.

I have also been plagued by auto_nodetitle changing my dates. It appears to change by 1 in whatever the smallest time value shown. I have a few other projects happening now, but I think I will start trying to debug this in the next week or two.

auto nodetitle is generated during hook_submit() and hook_presave(), date fields are changed (see date_field_update_helper()) in date_field_insert/update during field_attach_insert/update() which is run after that.

#1509434: date_field_update_helper() is run to late

Status:Active» Needs review
StatusFileSize
new1.17 KB

Another solution is to follow how node_preview() is doing it; call field load hooks. This also could fix yet unknown issues with other field types.

Ok, I was going to apply your patch, however I updated to the latest version of date and auto_nodetitle before doing it and my problem of the titles being off by one went away. So, I assume it is fixed, but I will wait for someone else to confirm before I change the status of this issue.

I'm having almost the same problem. I just updated to the dev version in hopes it would be fixed, but no.

I'm using a date token that includes the time. The time displayed as the token in the nodetitle is 5 hours ahead of the time entered in the date field. Users may not set their own timezone, and I checked to make sure I have to correct time zone selected in the regional settings.

I tested the token in a view, and it displays correctly.

Status:Needs review» Reviewed & tested by the community

I had the same problem of granularity (date field with granularity of Month) affecting auto node titles (timezone offset kicks back the date by a day, for me). This was running auto_nodetitle-7.x-1.0 and latest stable date-7.x-2.5 (which was released after #1509434: date_field_update_helper() is run to late was committed - see #20 above).

But the patch in #21 works for me, applied against auto_nodetitle-7.x-1.0. Worked on two sites, one running latest stable Date 7.x-2.5 , and another running earlier Date 7.x-2.2 (which was before #1509434: date_field_update_helper() is run to late).

the patch seems to work for me. i'm using dev version and date 2.5 - both for d7

the patch did nothing for me, the field I am trying to use for my title has date and time, using something like node:field_datetime:long results in a blank title.

Patch from #21 works for me (Auto Nodetitle 7.x-1.0, Date 7.x-2.5).

I have the Entity Tokens module -- part of http://drupal.org/project/entity -- installed and am using that token format, which has dashes instead of underscores; e.g. [node:field-mydatefield:short].

Thanks @casey
I was having the same problem using this.

This is my configuration:
- Drupal core 7.16
- Automatic Nodetitles 7.x-1.0
- Date 7.x-2.6
- Entity API 7.x-1.0-rc3 (Entity tokens is a sub module)

I have a date field called "field-session-date".
This is shared between content types.
I have a custom date format set up.
"field-session-date" produces this token [node:field-session-date:custom:m/d/Y]

The auto node title produced was always off by one day.
When I bulk updated the automatic nodetitles ("update automatic nodetitles" action @ http://www.mysite.ca/admin/content), the date in the automatic nodetitles was corrected.

I applied the patch in comment #21 posted by casey on March 30, 2012 http://drupal.org/node/1197278#comment-5805310.
The problem seems to have gone away.
Now, Automatic Nodetitles is producing the right date based on the token.

Similar situation as #28, applying the patch in #21 fixes the issue.

Note that it is possible to use the token in the following way in order to fix some of the issues above:

//Gets a loaded object from a router item => http://api.drupal.org/api/drupal/includes!menu.inc/function/menu_get_object/7
$node = menu_get_object();
//Define data for token replacement:
$data = array('node' => $node,);
//Use token for i.e. date-field 'enddate':
//Here I used a german date-format:
$enddate = 'Finished on [node:field-enddate:custom:d.m.Y]  [node:field-enddate:custom:H:i:s] Uhr';
//Do Token Replacement:
$enddate = token_replace($enddate, $data);
//Output date:
print $enddate;

I am confirming that the patch in #21 has fixed my automatic node title where it was one year less.

Can we get this committed ?

subscribing

Is my issue the same thing, similar, or different?
http://drupal.org/node/1917418

EDIT: Ok, nevermind. Patch in #21 worked for me.

Chiming in for a bump. Patch at #21 works great.

I don't know if this module is well maintained anymore. So I wanted to let everyone know if they are having problems they could use "Automatic Entity Label" module instead. It's the same concept as Automatic Nodetitles, it just works with any entity instead of just nodes. It will even import your old automatic nodetitles configurations for you.

The patch in comment #21 works for me too for Auto Nodetitle 7.x-1.0. Thanks.

The patch in comment #21 worked for me aswell. You made my day :)

Automatic Entity Label works to solve the issue i had with auto_nodetitle, and it seems like i could do a lot more with it. Thanks for pointing this out!

Patch #21 works for me as well. Lets get it committed.