This past week on two completely independent Drupal 5.10 sites of mine the views filter ability has stopped working for me with Date fields. I had views setup to show nodes whose CCK date field was greater than or equal to 'now,' for upcoming events, and on both sites we no longer get any results. If I remove the field from the Filter section of the view then I get all records (of course not filtered by date though).

What I don't get is how without making changes (these sites are not under active development) the bug appeared on both sites.

I was using Date 5.x-2.0-rc7 on both, and have updated (and run update script) to 5.x-2.3 on one to see if the problem is fixed, and it was not.

Using PHP 5.2.5, Drupal 5.10.

Here's the View export:

  $view = new stdClass();
  $view->name = 'training_events';
  $view->description = 'Shows only Training Event calendar_event nodes.';
  $view->access = array (
);
  $view->view_args_php = '';
  $view->page = TRUE;
  $view->page_title = 'Upcoming Training Events';
  $view->page_header = '';
  $view->page_header_format = '1';
  $view->page_footer = '';
  $view->page_footer_format = '1';
  $view->page_empty = '';
  $view->page_empty_format = '1';
  $view->page_type = 'teaser';
  $view->url = 'training-events';
  $view->use_pager = TRUE;
  $view->nodes_per_page = '50';
  $view->block = TRUE;
  $view->block_title = '';
  $view->block_header = '';
  $view->block_header_format = '1';
  $view->block_footer = '';
  $view->block_footer_format = '1';
  $view->block_empty = '';
  $view->block_empty_format = '1';
  $view->block_type = 'list';
  $view->nodes_per_block = '50';
  $view->block_more = TRUE;
  $view->block_use_page_header = FALSE;
  $view->block_use_page_footer = FALSE;
  $view->block_use_page_empty = FALSE;
  $view->sort = array (
    array (
      'tablename' => 'node_data_field_date_time',
      'field' => 'field_date_time_value',
      'sortorder' => 'ASC',
      'options' => '',
    ),
  );
  $view->argument = array (
    array (
      'type' => 'calendar_year',
      'argdefault' => '2',
      'title' => '%1',
      'options' => '',
      'wildcard' => '',
      'wildcard_substitution' => '',
    ),
    array (
      'type' => 'calendar_month',
      'argdefault' => '2',
      'title' => '%2',
      'options' => '',
      'wildcard' => '',
      'wildcard_substitution' => '',
    ),
    array (
      'type' => 'calendar_day',
      'argdefault' => '2',
      'title' => '%3',
      'options' => '',
      'wildcard' => '',
      'wildcard_substitution' => '',
    ),
  );
  $view->field = array (
    array (
      'tablename' => 'node_data_field_date_time',
      'field' => 'field_date_time_value',
      'label' => '',
      'handler' => 'content_views_field_handler_group',
      'options' => 'default',
    ),
    array (
      'tablename' => 'node',
      'field' => 'title',
      'label' => '',
      'handler' => 'views_handler_field_nodelink',
      'options' => 'link',
    ),
    array (
      'tablename' => 'node',
      'field' => 'body',
      'label' => '',
      'handler' => 'views_handler_field_body',
    ),
    array (
      'tablename' => 'node_data_field_contact_name',
      'field' => 'field_contact_name_value',
      'label' => '',
      'handler' => 'content_views_field_handler_ungroup',
      'options' => 'default',
    ),
    array (
      'tablename' => 'node_data_field_location',
      'field' => 'field_location_street1',
      'label' => '',
      'handler' => 'content_views_field_handler_group',
      'options' => 'default',
    ),
  );
  $view->filter = array (
    array (
      'tablename' => 'node',
      'field' => 'status',
      'operator' => '=',
      'options' => '',
      'value' => '1',
    ),
    array (
      'tablename' => 'term_node_2',
      'field' => 'tid',
      'operator' => 'OR',
      'options' => '',
      'value' => array (
  0 => '4',
),
    ),
    array (
      'tablename' => 'node_data_field_date_time',
      'field' => 'field_date_time_value_default',
      'operator' => '>=',
      'options' => 'now',
      'value' => '',
    ),
    array (
      'tablename' => 'node',
      'field' => 'type',
      'operator' => 'OR',
      'options' => '',
      'value' => array (
  0 => 'calendar_event',
),
    ),
  );
  $view->exposed_filter = array (
  );
  $view->requires = array(node_data_field_date_time, node, node_data_field_contact_name, node_data_field_location, term_node_2);
  $views[$view->name] = $view;

If it helps, here's the 'Dev queries' output from the dev module, for this view:

SELECT node.nid, CONCAT(node_data_field_date_time.field_date_time_value,'|',node_data_field_date_time.field_date_time_value2) AS node_data_field_date_time_field_date_time_value, node.title AS node_title, node.changed AS node_changed, node_data_field_contact_name.field_contact_name_value AS node_data_field_contact_name_field_contact_name_value, node_data_field_location.field_location_street1 AS node_data_field_location_field_location_street1, node_data_field_location.field_location_street2 AS node_data_field_location_field_location_street2, node_data_field_location.field_location_apt AS node_data_field_location_field_location_apt, node_data_field_location.field_location_city AS node_data_field_location_field_location_city, node_data_field_location.field_location_state AS node_data_field_location_field_location_state, node_data_field_location.field_location_zip AS node_data_field_location_field_location_zip, node_data_field_location.field_location_country AS node_data_field_location_field_location_country, node_data_field_location.field_location_other AS node_data_field_location_field_location_other, node_data_field_date_time.delta, node.type FROM {node} node LEFT JOIN {term_node} term_node ON node.nid = term_node.nid LEFT JOIN {term_hierarchy} term_hierarchy ON term_node.tid = term_hierarchy.tid LEFT JOIN {content_field_date_time} node_data_field_date_time ON node.vid = node_data_field_date_time.vid LEFT JOIN {content_type_calendar_event} node_data_field_contact_name ON node.vid = node_data_field_contact_name.vid LEFT JOIN {content_type_calendar_event} node_data_field_location ON node.vid = node_data_field_location.vid WHERE (node.status = '1') AND (term_node.tid IN ('4')) AND (DATE_FORMAT(STR_TO_DATE(node_data_field_date_time.field_date_time_value, '%Y-%m-%%dT%T'), '%Y-%m-%%d\T%H:%i') >= '2008-09-28T22:49') AND (node.type IN ('calendar_event')) AND ((STR_TO_DATE(node_data_field_date_time.field_date_time_value2, '%Y-%m-%%dT%T') >= '2008-01-01 00:00:00' AND STR_TO_DATE(node_data_field_date_time.field_date_time_value, '%Y-%m-%%dT%T') <= '2007-12-31 23:59:59')) ORDER BY node_data_field_date_time_field_date_time_value ASC

Thank you for reading this, let me know if additional info is needed.

Comments

jbomb’s picture

I'm having this problem too. With drupal 5.10, date 5.x-2.3 and views 1.6

I was able to resolving by changing the following in

date_api_elements.inc line 400;

  foreach ($element['#value'] as $field => $field_value) {
    if (substr($field_value, 0, 1) == '-') {
      $element['#value'][$field] = '';
    }
  }

to

  if (is_array($element['#value']) {
    foreach ($element['#value'] as $field => $field_value) {
      if (substr($field_value, 0, 1) == '-') {
        $element['#value'][$field] = '';
      }
    }
  }
millions’s picture

That code gave me an error saying there was an unexpected { in line 400.

I'm having the same problem, my events show up, but will not disappear when the date - to date time passes. I'm using a filter with greater than or equal to now for the date-to date to display...

jbomb’s picture

sorry about that ... should be

  if (is_array($element['#value'])) {
    foreach ($element['#value'] as $field => $field_value) {
      if (substr($field_value, 0, 1) == '-') {
        $element['#value'][$field] = '';
      }
    }
  }
millions’s picture

Thanks that worked, I had to go to my upcoming events view and edit -> save but then it worked fine!

ontoligent’s picture

I tried this, but with no effect. I'm using Date version 5.x-2.4.

karens’s picture

Status: Active » Fixed

I can't come up with any way to replicate this situation, but the fix certainly won't hurt anything, so I'm going to commit it.

karens’s picture

I should say I understand that there are ways this could happen and the fix is the right one for those situation (when the validator is receiving a string instead of an array), I just couldn't come up with a scenario to test it.

karens’s picture

@rca2t - you must have a different problem, this isn't a fix for anything that might be broken in filters, it's for this specific problem which is an iso field that is using a date selector in an exposed filter to find >= now. If you still have problems in the latest code you need to provide complete details about what you see and where you see it, but move that to a separate issue.

Status: Fixed » Closed (fixed)

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