Date filters not working in Views

linuxbox - June 12, 2007 - 21:46
Project:Date
Version:5.x-1.6
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:duplicate
Description

I have a CCK Content type that contains a start date field and end date field. I am trying to create a view that allows users to pick a from and to date and show all nodes whose start is after the "from" date before the "to" date. I added two filters and exposed them, however, no filtering is being done. The problem seems to occur in date_views.inc: date_views_timestamp_filter_handler The value of $type is 'DATE' which falls to the default block and returns without adding a where clause. If I comment out lines 156 and 159 the where clause gets added and the filter works correctly. I'm not really sure what the function SHOULD do though as the comments are extremely sparse. I will provide any help necessary to get a patch made.

#1

imrook - June 13, 2007 - 16:03

Okay, I looked at the code a little closer and I think I have found a logic error.

if ($field_type == 'int' && (empty($value) || !($value == 'now' || date_is_valid($value, DATE_UNIX)))) {
return;
}
elseif (empty($value) || !($value == 'now' || date_is_valid($value, DATE_ISO))) {
return;
}
break;

Examine the case where $value is a valid ISO date:
In the first if statement $value == 'now' is FALSE and date_is_valid($value, DATE_UNIX) is FALSE
The value is then complimented to become true and the function returns.
I am using the following code on my site and would like to have it reviewed before making a patch.

if (empty($value)) {
return;
}
elseif (!($value == 'now' || date_is_valid($value, DATE_ISO) || date_is_valid($value, DATE_UNIX))){
return;
}
break;

#2

imrook - June 13, 2007 - 16:06

Sorry, used the wrong tags:
Replace

        if ($field_type == 'int' && (empty($value) || !($value == 'now' || date_is_valid($value, DATE_UNIX)))) {
          return;
        }
        elseif (empty($value) || !($value == 'now' || date_is_valid($value, DATE_ISO))) {
          return;
        }
        break;

With
        if (empty($value)) {
          return;
        }
        elseif (!($value == 'now' || date_is_valid($value, DATE_ISO) || date_is_valid($value, DATE_UNIX))){
          return;
        }
        break;

#3

Benjamin Melançon - August 16, 2007 - 16:12

This fix works. It didn't before. My client will be using it and seeing if any new problems pop up, but if it's still good for linuxbox and imrook, we should get this fix in. I can also roll a patch against head.

#4

jscheel - August 31, 2007 - 16:52
Version:5.x-1.x-dev» 5.x-1.6

I've been tracking down this bug. The problem occurs when date_sql() in date.inc writes out the interval offset. Verify by removing the interval in a sql statement generated by date_sql().

#5

Aren Cambre - June 9, 2008 - 16:42

http://drupal.org/node/190289 was marked as a duplicate of this one.

#6

avior - July 6, 2008 - 14:20

Hi
Is this patch included in the current release ?
what is the status of this ?

#7

dugh - July 9, 2008 - 04:48

See http://drupal.org/node/277420
I still see the issue although it has been marked as fixed with the latest dev version.

#8

rgeorgy - July 9, 2008 - 19:34

me too still facing the same problem

#9

Aren Cambre - July 9, 2008 - 21:02
Status:active» duplicate

Marking as duplicate since the issue referenced in #7 is about the same problem and is getting a lot of love right now.

 
 

Drupal is a registered trademark of Dries Buytaert.