Hi there!

CCK 5.x-1.3, Date 5.x-1.3, Views 5.x-1.5

I have a filter in my View that's set to:

Datestamp: Date - Date (field_date) | greater than or equal to | now | -86400

While it should technically be showing two nodes it instead shows none.

I turned on Devel query log and it appears it's trying to do:

SELECT count(node.nid) FROM node node LEFT JOIN content_type_date node_data_field_date ON node.vid = node_data_field_date.vid LEFT JOIN content_type_date node_data_field_location ON node.vid = node_data_field_location.vid WHERE (node.type IN ('date')) AND (node.status = '1') AND ((FROM_UNIXTIME(node_data_field_date.field_date_value) - INTERVAL -18000 SECOND) + INTERVAL - -86400 SECOND>='ERROR')

It's very hard for something to be greater than or equal to 'ERROR' ;)

I threw some watchdog() statements into date_views_filter_handler() in date_views.inc. Here's what I've been able to figure out...

  $totype = $filterinfo['type'];
  $type = substr($totype, 0, 3) == 'to|' ? substr($totype, 3) : $totype;
  if ($totype == $type) {
    $value = $filter['value'];
  }
  else {
    $value = $filter['value2'];
  }
  /// here, $value is 'now'.
...
  $db_info = content_database_info($field);
  $value   = $db_info['columns']['value']['column'];
  /// now, $value is field_date_value ... the name of the date column.
...
  switch ($filterinfo['type']) {
    case ('DATE'):
      $date    = $value == 'now' ? "NOW()" : "'". str_replace('T', ' ', date_custom2iso($filter['value'], $formats['input']['text'])) ."'";
      break;
    /// $date becomes 'ERROR'... presumably because it's expecting $value to be something like 'now' and not a column name.

Attached patch renames the second $value to $column instead. Don't know if that's the right fix, but it appears to work.

CommentFileSizeAuthor
#3 date_views.inc_.patch1.07 KByched
date-filter.patch1.32 KBwebchick

Comments

karens’s picture

Status: Needs review » Fixed

That's the new filters just added so you can filter by both from and to dates and they needed a few other tweaks besides this problem, so this wasn't exactly the right fix. I also did some cleanup of the timezone handling. Committed to all branches.

Anyway, thanks for the report. It should be fixed now.

yched’s picture

Status: Fixed » Active

Karen, it seems there are still issues (in latest 4.7 branch at least)
in the generated query, the 'delta' param is showing on both sides of the comparison operator :
something like 'WHERE value + delta > now() + delta'
resulting in the 'delta' param having no effect at all.

yched’s picture

StatusFileSize
new1.07 KB

attached patch should fix it - at least by looking at the previous version of the code.
I'm never sure whether the offset is to be added to the left or the right side of the comparison op :-) I removed the one on the right side

yched’s picture

Status: Active » Needs review
karens’s picture

Duplicate report at http://drupal.org/node/124777.

karens’s picture

Duplicate report at http://drupal.org/node/124776.

dodorama’s picture

same issue here

karens’s picture

Status: Needs review » Fixed

Just committed a fix. Needed a slightly different approach than suggested by yched since I needed the timezone adjustment to get added in, too, just needed to get the option value only displayed on one side of the equation. While I was at it, I did it a bit differently to make it easier to see that the option is altering the 'now' value rather than the date value.

karens’s picture

I still see some problems, but I'm dealing with them with the patch in http://drupal.org/node/123365, so don't re-open this issue, use that one instead.

dodorama’s picture

Is it correct that this is not fixed in release 5.x-1.4 ?
Cause I'm stil experiencing this and I'm not sure if #9 refer to 5.x-1.3.
In case, does this patch solve the issue?
If yes, waiting for a new release, can you provide a patch (the applied one isn't provided in the issue queue) since this is (I guess) a critical feature;
at least for me ;)

dodorama’s picture

Ok.
I'm working too much.
Everything is Ok. I simply filtered the view using the wrong date_field.

Anonymous’s picture

Status: Fixed » Closed (fixed)