I have several views which use a date field. These views are used to display an agenda. I've put a filter on these views which select agenda-items with a date "greater than or equal to" "now". Now I have a problem that an agenda-item which had as date/time "13-04-2008 16:00" wasn't shown in the list. First I thought there was a timezone or DST problem, so I added "-3600" in the option-field of the specific filter, but now I noticed the agenda-item wasn't shown at 14.55, so that's over an hour before the activity is supposed to start.
Now I really have no clue what might be the real cause of this behavior. If I create a simple PHP-script which uses the date-function to display the current date/time, the correct date/time is shown.

By the way, of course this agenda-item is just an example. The same happens with all other agenda-items.

CommentFileSizeAuthor
#8 date_api_sql_offsetForNow.patch1.15 KBptone

Comments

ptone’s picture

What kind of view? List, Table?

What fields do you have displayed?

Any other filters?

-P

pvanderspek’s picture

The view can be shown as a full page. In that case, I use a table view.
I also have a block, which only shows the first five items, and this is shown as a list view.

The view has three fields:
- date
- taxonomy term
- node title

And two more for editors:
- node edit link
- node delete link

Furthermore, I use three filters:
- node published should equal yes
- node type should be agenda
- date should be greater or equal to now

Finally, I sort the list/table based on the date value.

ptone’s picture

Well two things to track down.

take out the date filter and make sure all your agenda items are showing (narrows it to a date issue).

Make sure that "now" is in the options box without any quotes

-P

troym559’s picture

I am having the same problem. I have created a view and i'm trying to filter the nodes to only display nodes that have a cck date field that is "greater than or equal to" = now. The problem is that when i do i am only getting nodes that have tomorows date and greater. It is not listing nodes that have todays date. If i try usning now-3600 it displays all the nodes regardless of the date.

Please Help

ptone’s picture

OK, now I see what you are talking about. when the test is >= now - today's date doesn't work.

In a test between two versions of my site, it looks like this is fixed in the latest 2x dev builds.

-P

jesss’s picture

I have the most recent version of 2x-dev installed, but I'm still having this problem. When I try to filter by date is less than or equal to now, my view is empty. Any ideas on how to fix this?

robbiew’s picture

Same here -- I have the most recent 2x-dev installed and I'm having the same problem.

ptone’s picture

Status: Active » Needs review
StatusFileSize
new1.15 KB

First off I retract my statement that its fixed in the latest snapshot, I tested further and its not.

There are two issues here, one is a bug, the other may be considered a feature request or clarification.

I've submitted the feature request as its own, issue, it has to do with the "now" option not working for dates of Y-M-D granularity as expected.

http://drupal.org/node/251994

There are two bugs preventing this from working, one is just a typo.

Offsets like +1 days are never applied. This is because the date_sql code ignores offsets for field of "NOW()" so NOW() gets passed right back.

in date_views.inc:
$date = $value == 'now' ? date_sql('NOW', 'NOW()', $field_type, intval(date_views_offset($field) + $adjust)) : "'$value'";

doesn't do anything meaningful (an offset is given, but never applied) because if you trace this through

date_sql
date_sql_extract
date_sql_field

you get to the code:

  if ($field == 'NOW()') {
      return $field;
  }

This skips any application of the offset param in date_sql_field

so the sql for the where clause always looks like:

STR_TO_DATE(node_data_field_meeting_date.field_meeting_date_value, '%Y-%m-%%%%dT%T') >= NOW()

but it should look like:

STR_TO_DATE(node_data_field_meeting_date.field_meeting_date_value, '%Y-%m-%%%%dT%T') >= ADDTIME(NOW(), SEC_TO_TIME(-172800))

In tracking this down there is also a bug where all offsets get their amounts reversed due to the old asignment vs test gotcha/typo that I also regularly make ;-)

so the line:
if (!empty($offset) && $offset_op = '-') {

becomes

if (!empty($offset) && $offset_op == '-') {

I've attached a patch made against the April 22 5.x-2.x dev snapshot that fixes the above two issues.

I'm not sure if there are other places where an offset is given with NOW() that would be broken by having the offset applied. I can't think of why anything would expect the current behavior, but that's what review is for ;-)

Note that given that "now" uses a timestamp, if you are using a date without time, and you want today and future items, you should put in the filter:

greater than or equal to "now -1 day"

This will give you today and future dates.

-P

ptone’s picture

Version: 5.x-1.8 » 5.x-2.x-dev
jesss’s picture

I just applied the patch, and it doesn't seem to fix the problem. My views that rely on filtering relative to now are still empty.

pvanderspek’s picture

Version: 5.x-2.x-dev » 5.x-1.8

I'm sorry for the delay, but I didn't have time to tried out your suggestions as per #3 until today.
In any case, without the date filter every agenda-item ever made shows up, so it is a date-issue.

Furthermore, agenda-items for today DO show up. For instance, where I live it is now 01-05 14.32. If I create an agenda-item for 15.00 it isn't shown, but if I change the time to 16.00 it is.

I'm still working with the filter "greater or equal to now" with an ofsett of -3600, but if I remove that ofsett the behaviour doesn't change! That is, the ofsett doesn't seem to have any effect!

I hope this information helps you to narrow down the problem further.

deverman’s picture

Version: 5.x-1.8 » 5.x-2.x-dev

I believe I am still experiencing this problem with the 2.0 development version of the module. I have a schedule of events that happen every day. I am trying to make a block that displays the next event as it happens that day using views. I have used the date repeating function as this event happens every day. I have set the filter to show only published nodes of my schedule type whose date is greater than "NOW". I was having a problem with the correct entry coming up but I found that there was different behavior when I use "now" vs. "NOW". The case seems to matter and on this view "now" was not working properly and "NOW" seems to work. I will wait for the view to run through the day to test fully. I also have another list of events that are upcoming which do not repeat. After upgrading to the 2.0 release candidate this view did not work. I had to upgrade to the development release and then edit the view as the now option did not convert properly. After editing I changed the option to "now" and it seemed to work though most of the events are a few days from now. I then changed it to "NOW" and it showed events from as far back as February.

To sum up on one upcoming event view "NOW" works and on another "now" works. If I can provide any more information to debug this please let me know.

(I am using Drupal 5.7)

deverman’s picture

I just checked my block to see if the block filtering dates greater than "NOW" worked as the time for an even passed and unfortunately the filter did not work and the next event was still the same so this function seems quite broken. Let me know what info is needed from my side to help fix it.

karens’s picture

Status: Needs review » Needs work

I'm doing a complete rewrite of the filter handling. I found a number of places that it might fail and have come up with a much more stable way of doing it which I will commit in the next day or two. I'm on the road today so can't get it done until I get back.

karens’s picture

Status: Needs work » Fixed

OK, I just committed my rework of the SQL used to create the filters and arguments. The code is cleaner and the queries are easier to understand (and debug) and it should now properly handle timestamps as well as ISO dates (sometimes the previous code got that wrong.)

deverman’s picture

I installed the updated development version of the date module. When doing the database update I did get a error message "warning: array_merg() argument #2 is not an array...". I went ahead and used the module and so far things seem to be working. The block I was updating to show the next event seems to be working.

karens’s picture

@deverman - I was missing an empty return value in the update which is now fixed. It won't affect anything and you should be fine.

jjohnsonBLC’s picture

I fixed a problem I was having with (I think) the most recent -dev version of Date for 5.x-2.x. My problem was similar to the original post. The "option" field in the filter section would not let me do anything like "now +1 day".

In the sql_where_date function of date_api_sql.inc, I changed the first elseif to an if. I believe this is around line 372.

Note: I am not a solid programmer; I just know I had a problem and making this change fixed it for me. I also have no clue on how to make patches, or even the proper procedure for letting someone know about possible fixes like this.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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