I'm using CCK to create a custom content type ("Date") with field_date (a text field with strotime validation). field_date has a custom input and display format: Y. So it only takes a four-digit year parameter. That's because I'm making a timeline that spans from 1304 to 2004, and anything more granular than years is too much to worry about on that scale. (The granularity is also set to Years.) No time zone conversion. There is an optional To: date and the field is required.

When I type a date into field_date and submit the node, the date gets processed and comes out a year earlier than intended. For example, if I write "2008" into field_date and submit the node, the displayed result is "2007."

Thoughts? Help? Thanks. PHP5.2, D5.7, MySQL. The site has basically only a few core modules (Menu, Taxonomy), Date, and the Timeline module.

CommentFileSizeAuthor
#24 date.install.patch924 bytesbcn
#12 screenshot.jpg224.09 KBicecreamyou
#12 datesettings.jpg141.93 KBicecreamyou

Comments

icecreamyou’s picture

By the way, this happens every time the node gets submitted, including if it gets edited. So for example, if the node was created with 2008 in field_date and submitted, it would say 2007; if it was then edited and re-submitted (but the date wasn't changed) it would say 2006; and so on. This is something of a problem because I have a user that's going to be repeatedly editing each node.

icecreamyou’s picture

Specifically, I discovered that the date gets assigned to 30 Nov [Inputted Year - 1] 00:00:00 GMT which is quite strange.

icecreamyou’s picture

After more exploration, I think this occurs in date_api.module in the function date_diff().

Lines 732-736:

        else {
          $item_diff = 12 - $item1;
          $item_diff += intval(($year_diff - 1) * 12);
          return $item_diff + $item2;
       }

That's the only place in date_api.module or date.module that I can find where 1 might possibly be subtracted from the year.

karens’s picture

Status: Active » Postponed (maintainer needs more info)

That's not the problem, date_diff() is not used on the node submit. Update to the latest dev version of date and see if you still have problems.

icecreamyou’s picture

Tested the latest 2.x dev. This is so weird.

When a node is first created, no matter what year is put in, the result is the year 1970. When it's updated, the year increments by one - the opposite behavior from before.

I am very confused.

icecreamyou’s picture

Version: 5.x-2.0-rc » 5.x-2.x-dev

Updating to dev, even though it really applies to all 2.x releases.

karens’s picture

I have no problem and can't replicate this. I fixed a similar problem recently and it works fine for me now. Please paste an export of the date field you created so I can see how you set it up.

icecreamyou’s picture

All I get when I go to export the field is this message:

This feature is not yet functional.

...but I think I have something significantly wrong with my Date installation. Maybe an extraneous file from an earlier version is still there messing things up. I'll retry everything and see how it goes.

icecreamyou’s picture

Okay, I just removed the date module folder and put in a fresh copy of it from d.o - I have the same problem. I didn't want to uninstall because I wasn't sure if the data from my nodes would be erased.

Since I updated from 2.0rc to 2.x-dev though, it's gone back to 1.x behavior (i.e. no dates allowed before 1970). That makes me think there's a larger problem here.

karens’s picture

This feature is not yet functional

What version of everything are you using? You should not be seeing that anywhere. Are you trying to use the HEAD version of CCK or Date?

icecreamyou’s picture

You told me to try 2.x-dev, so I did. I'm using this one.

icecreamyou’s picture

StatusFileSize
new141.93 KB
new224.09 KB

Attached is a screenshot of my modules page.

EDIT: I tried this with and without the Date Popup module enabled. Right now it's disabled. Also, I've added a screenshot of the date field's settings page.

karens’s picture

Turn on Content Copy so you can create an export of your field.

icecreamyou’s picture

No one ever told me it was *Content Copy* and not *Date Copy* that had to be enabled (by the way, I had Date Copy enabled but I disabled it before taking that shot). :D

Here's the export.

See also my last post--I added a screenshot of the date field's settings page.

$content[type]  = array (
  'name' => 'Date',
  'type' => 'date',
  'description' => '',
  'title_label' => 'Title',
  'body_label' => 'Description',
  'min_word_count' => '0',
  'help' => '',
  'node_options' => 
  array (
    'status' => true,
    'promote' => false,
    'sticky' => false,
    'revision' => false,
  ),
  'old_type' => 'date',
  'orig_type' => '',
  'module' => 'node',
  'custom' => '1',
  'modified' => '1',
  'locked' => '0',
);
$content[fields]  = array (
  0 => 
  array (
    'widget_type' => 'date_text',
    'label' => 'Date',
    'weight' => '0',
    'default_value' => 'blank',
    'default_value_code' => '',
    'default_value2' => 'same',
    'default_value_code2' => '',
    'input_format' => 'Y-m-d H:i:s',
    'input_format_custom' => 'Y',
    'advanced' => 
    array (
      'label_position' => 'within',
      'text_parts' => 
      array (
        'year' => 0,
        'month' => 0,
        'day' => 0,
        'hour' => 0,
        'minute' => 0,
        'second' => 0,
      ),
    ),
    'increment' => 1,
    'year_range' => '-3:+3',
    'description' => '',
    'required' => '1',
    'multiple' => '0',
    'repeat' => 0,
    'todate' => 'optional',
    'granularity' => 
    array (
      'year' => true,
      0 => 1,
      'month' => false,
      'day' => false,
      'hour' => false,
      'minute' => false,
      'second' => false,
    ),
    'output_format_date' => 'Y M j',
    'output_format_custom' => 'Y',
    'output_format_date_long' => 'l, F j, Y - H:i',
    'output_format_custom_long' => 'Y',
    'output_format_date_medium' => 'Y, F j - g:ia',
    'output_format_custom_medium' => 'Y',
    'output_format_date_short' => 'Y M j - H:i',
    'output_format_custom_short' => 'Y',
    'tz_handling' => 'none',
    'timezone_db' => 'UTC',
    'field_name' => 'field_datestart',
    'field_type' => 'date',
    'module' => 'date',
    'label_position' => 'within',
    'text_parts' => 
    array (
    ),
    'display_settings' => 
    array (
      'label' => 
      array (
        'format' => 'inline',
      ),
      'teaser' => 
      array (
        'format' => 'hidden',
      ),
      'full' => 
      array (
        'format' => 'default',
      ),
    ),
  ),
);
icecreamyou’s picture

This is really annoying.

I use date on another of my websites, and I'm using the same version of the module on that site as the one I'm having the problem with; but on my other site, it's working just fine.

...I'll work on trying to figure out what's different. Thanks for any help so far, and of course I'm still interested in any comments, questions, or solutions you might have.

karens’s picture

The granularity array looks funny -- that zero doesn't belong in there. Try pulling up the field edit screen, double-check all the settings, and re-save it (even if the settings look OK). Then try another export and see if the granularity loses that zero. If so, try creating your date again.

icecreamyou’s picture

I tried what you said. I also tried changing some settings, saving, then changing them back. The zero is still there.

Then I removed the zero manually from the text and imported the result into a new field for the Page content type. The same thing was happening, so I exported the field from the Page content type - and the zero had reappeared.

Will I lose any data from existing nodes if I uninstall (and then reinstall) Date? Will that even help anything?

karens’s picture

It sounds like there is a bug in the program putting that zero in there, so I need to figure out what it is.

icecreamyou’s picture

Well, I haven't been able to find any differences between my sites that would affect Date.

I don't know much PHP, but let me know if there's anything more I can do.

icecreamyou’s picture

A possible clue: I upgraded to the latest dev version just now and ran update.php, which gave these errors:

    * warning: include_once(./modules/cck/includes/content.admin.inc) [function.include-once]: failed to open stream: No such file or directory in /home/[root]/domains/[domain]/public_html/[subdomain]/modules/date/date/date.install on line 8.
    * warning: include_once() [function.include]: Failed opening './modules/cck/includes/content.admin.inc' for inclusion (include_path='.:/usr/local/lib/php') in /home/[root]/domains/[domain]/public_html/[subdomain]/modules/date/date/date.install on line 8.
    * warning: include_once(./modules/cck/includes/content.admin.inc) [function.include-once]: failed to open stream: No such file or directory in /home/[root]/domains/[domain]/public_html/[subdomain]/modules/date/date/date.install on line 8.
    * warning: include_once() [function.include]: Failed opening './modules/cck/includes/content.admin.inc' for inclusion (include_path='.:/usr/local/lib/php') in /home/[root]/domains/[domain]/public_html/[subdomain]/modules/date/date/date.install on line 8.
okeedoak’s picture

I have the same subtract-a-year problem here. And I just received the same errors you did in #20. I went from the rc to the latest dev, then ran update.php.

okeedoak’s picture

Here's an export:

$content[fields]  = array (
  0 => 
  array (
    'widget_type' => 'date_text',
    'label' => 'Year',
    'weight' => '0',
    'default_value' => 'now',
    'default_value_code' => '',
    'default_value2' => 'same',
    'default_value_code2' => '',
    'input_format' => 'Y-m-d H:i:s',
    'input_format_custom' => '',
    'advanced' => 
    array (
      'label_position' => 'above',
      'text_parts' => 
      array (
        'year' => 0,
        'month' => 0,
        'day' => 0,
        'hour' => 0,
        'minute' => 0,
        'second' => 0,
      ),
    ),
    'increment' => 1,
    'year_range' => '-3:+3',
    'description' => '',
    'group' => 'group_season_and_year',
    'required' => '1',
    'multiple' => '0',
    'repeat' => 0,
    'todate' => '',
    'granularity' => 
    array (
      'year' => true,
      0 => 1,
      'month' => false,
      'day' => false,
      'hour' => false,
      'minute' => false,
      'second' => false,
    ),
    'output_format_date' => 'Y M j',
    'output_format_custom' => '',
    'output_format_date_long' => 'l, F j, Y - H:i',
    'output_format_custom_long' => '',
    'output_format_date_medium' => 'D, m/d/Y - H:i',
    'output_format_custom_medium' => '',
    'output_format_date_short' => 'm/d/Y - H:i',
    'output_format_custom_short' => '',
    'tz_handling' => 'none',
    'timezone_db' => 'UTC',
    'field_name' => 'field_newsletter_section_year',
    'field_type' => 'date',
    'module' => 'date',
    'label_position' => 'above',
    'text_parts' => 
    array (
    ),
  ),
karens’s picture

Status: Postponed (maintainer needs more info) » Fixed

#20 was the clue I needed. That is a typo that used the file naming convention used in CCK D6 instead of the one used in CCK D5. Fix committed.

Thanks, and sorry!

bcn’s picture

Status: Fixed » Needs review
StatusFileSize
new924 bytes

Hi Karen,

I think the fix you made for this also has a small typo...

-  include_once('./'. drupal_get_path('module', 'content') .'/includes/content_admin.inc');
+  include_once('./'. drupal_get_path('module', 'content') .'/content_admin.inc');

The 5.x version of cck doesn't have an 'includes' sub-directory.

karens’s picture

Status: Needs review » Fixed

That's what happens when I try to do too many different things at once :)

Thanks, fix committed.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.