I have a date field on a node type. This date field is set to have a from and a to date. The granularity is down to the minute.

I have my node title, via Automatic Nodetitles, set to be this: [field_date-month] [field_date-yyyy].

No matter what date I have in the field, the value that ends up in the node title is January 2007.

I am using a Datestamp field to do this.

Comments

Aren Cambre’s picture

Title: Incorrect token-based replacement pattern being sent to my node title (via Automatic Nodetitles) » All replacement patterns based on 0:00 Jan. 1, 2007

Just now, I tried using [field_date-timestamp] and [field_date-to-timestamp]. In both cases, the resulting date code is 1167609600, which is Mon, 01 Jan 2007 00:00:00 GMT.

I also tried a couple of additional replacement patterns, and it appears that no matter what I use, the returned value will be based off 1167609600.

Aren Cambre’s picture

Wow, something is really messed up. I just created a Date field type (in addition to the previously-created Datestamp field type), and it too appears to return all values based off timestamp 1167609600.

Aren Cambre’s picture

I may have found the problem. token_cck.inc (line 263) calls date_show_date($date, 'Y'). That leads to date.inc (line 487), which has date_format_date($format_string, date_fuzzy_stamp($date->local)). The 2nd parameter of that function leads to execution of the following date.inc code (lines 531-545):

/**
 *  Create a valid timestamp that can be used for date formatting
 *  even if only partial date info is available,
 *  i.e. for an iso date with month and year only
 */
function date_fuzzy_stamp($datetype) {
  if ($datetype->timestamp) {
    return $datetype->timestamp;
  }
  else {
    return date_gmmktime(array(
      'year'   =>  ($datetype->parts['year']    ? $datetype->parts['year']    : date('Y')),
      'mon'    =>  ($datetype->parts['mon']     ? $datetype->parts['mon']     : 1),
      'mday'   =>  ($datetype->parts['mday']    ? $datetype->parts['mday']    : 1),
      'hours'   => ($datetype->parts['hours']   ? $datetype->parts['hours']   : 0),
      'minutes' => ($datetype->parts['minutes'] ? $datetype->parts['minutes'] : 0),
      'seconds' => ($datetype->parts['seconds'] ? $datetype->parts['seconds'] : 0),
      ));
  }
}

It's uncanny how the date stamp that is used ends up having the exact same values as the else clause.

Note that the date.inc line numbers are from the Aug. 8 version of 5.x-DEV.

Aren Cambre’s picture

Well, I looked more at the code, and it looks like the default date/time is only used in its entirety if the date object passed to date_fuzzy_stamp is empty?

Working backwards, it looks like this may happen if token's date_token_values's 2nd parameter ($object) is null? But grepping my entire Drupal install and searching the entire database, I cannot find any instance of use of the date_token_values function. So I am confused.

Aren Cambre’s picture

I just created a new Date field and accepted all defaults (except for the one setting I had to change due to this bug), and I still get the same behavior.

(Yes, I changed the replacement patterns to use the new date field I just created.)

Aren Cambre’s picture

Title: All replacement patterns based on 0:00 Jan. 1, 2007 » All replacement patterns use 0:00 Jan. 1, 2007

(Shortening title.)

Aren Cambre’s picture

Title: All replacement patterns use 0:00 Jan. 1, 2007 » All Date module replacement patterns use 0:00 Jan. 1, 2007
Project: Date » Token

I have a gut feeling this might be a problem with the Token module. Switching to Token.

amanire’s picture

I'm having the same problem with every date or time sensitive field except for [field_(cck field)-value] and [field_(cck field)-view]. This seems pretty vital, considering that the timestamp token is the only way to represent a time field, without branching from the module code.

Aren Cambre’s picture

So you're saying this happens with modules other than Date?

amanire’s picture

No, sorry if I was unclear. The problem for me really is using the [field_(cck date field)-timestamp] token, where (cck date field) is one of several cck date fields that I'm using. I don't know whether the bug is originating in the Date module or in the Token module.

amanire’s picture

I think this may be a duplicate of this issue: http://drupal.org/node/114610

I haven't had a chance to test the patches yet, though.

Aren Cambre’s picture

Status: Active » Closed (duplicate)

I think you're right. I've marked this one as duplicate.