Hello,

Problem

When using Views and an exposed date filter with a granularity set to 'Month' (so that only 'Year' and 'Month' get selected), the filter does not work - it runs the filter, but instead uses the current date rather than the date asked for.

Note that the second time the filter is run, then it works better. When testing this issue, it is best to reload the page afresh (without submitting any searches) between tests.

Analysis

With the granularity set to Month, the search form initialy sets the day to '0' (as a hidden value). This causes 'date_is_valid' to return false ; and thus the search uses the default value (current date) instead.

I'm not sure what happens the second time you run the filter - the default value for day is not '0' anymore, but seems to be the current day

Thanks for this module :) Please let me know if you need any extra information, or if I can help you sort out this issue. I'll set my filter's granularity to day for now :)

Comments

Alice Heaton’s picture

With a bit more detail :

In the class date_api_filter_handler, the method date_filter calls date_make_date (on line 369 of date_api_filter_handler.inc as of rc4).

date_make_date returns the current date because, as per the original bug report, date_is_value returns false.

Hope this is a bit more helpful.

karens’s picture

Status: Active » Fixed

I've committed some changes that I think get this working right.

raspberryman’s picture

Status: Fixed » Active

Hi Karen,

Testing with DRUPAL-6--2 that you committed today...

The changes work when:

  1. I set the filter granularity to Day.
  2. Resave the filter configuration page.
  3. Set the filter granularity back to Month.

However, if I make any further changes after step #3 to the filter configuration page, such as changing the absolute date or exposing the filter, the bug described above resumes: "it runs the filter, but instead uses the current date rather than the date asked for"

Thanks for your awesomeness!

raspberryman’s picture

More info...

When I set the granularity to Day, the Views Filters list reads:
Date: Date Content: My Date Field - (field_mydatefield) = 2008-12-11 00:00:00

When I change the granularity to Month, the list reads:
Date: Date Content: My Date Field - (field_mydatefield) = 2008-12-11 00:00:00

And the filter works!

When I change the filter configuration page in any way, however, the list reads:
Date: Date Content: My Date Field - (field_mydatefield) = 2008-12-00 00:00:00

The day is set to '00'. At this point, the filter breaks, and the query uses the current date instead.

raspberryman’s picture

Just out of curiosity, I tested with today's DRUPAL-6--2. Still no luck.

raspberryman’s picture

This is my temporary hack to get things working.

// date_api_filter_handler.inc line 472
- $date = date_make_date($complete_date);
+ $date = date_make_date($complete_date, $this->date_handler->db_timezone, DATE_DATETIME, array($granularity));

I must admit that the date module confuses me and I commend Karen for being able to keep all these details straight :)

karens’s picture

Status: Active » Fixed

I committed a number of fixes to the filter this morning and this should be working.

Status: Fixed » Closed (fixed)

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

vinoth.3v’s picture

HI

have any possibilities to filter out only by "Month" (with out Year) ?
because it may be use full to display this month D.O.B s??

Thanks

zoo’s picture

@#9

Hello, so did you get it working filtering only by month?

Could you please tell how here: http://drupal.org/node/896362?

Thank you, zoo