I need the date module, when being used as a filter for a view, to be able to use a relative date (like 'this Sunday'). I hacked around a bit on date_views.inc and came up with the code below. On the filter for the view, I'm using '@RELthis sunday' as the filter value.

  switch ($filterinfo['type']) {
    
    case ('DATE'):
      if ( substr($filter['value'], 0, 4) == "@REL") {
        $date = "'" . str_replace('T', ' ', date_unix2iso(strtotime(substr($filter['value'], 4)))) . "'";
      }
      else {
        $date    = $filter['value'] == 'now' ? "NOW()" : "'". str_replace('T', ' ', date_custom2iso($filter['value'], $formats['input']['text'])) ."'";
      }
      break;
    default:
      $date = $filter['value'] == 'now' ? date_sql($filterinfo['type'], "NOW()", $field_type, '') : $filter['value'];
      break;
  }

This is getting the correct date into the SQL where clause, the I can't figure out how to get the correct time. Somehow I've got to figure out how to get the correct timezone into the date_unix2iso function (assuming I need that function at all).

I think this would be a valuable addition to this module. In my case, I'm doing a website for my church. We have the church assembly times on the site, so I created a CCK node type and associated view. It is _great_ that I can filter the view based to show the assembly nodes where the assembly date is greater than now(). But, if my users don't enter an assembly for this Sunday, but they do for next Sunday, then I don't want to show the block on the page at all. In other words, I only want to show the assembly information when there is an assembly entry for this Sunday.

If I can figure out this timezone issue, I'll be happy to roll a patch for consideration.

Comments

KarenS’s picture

Version: 5.x-1.x-dev » 7.x-1.x-dev

Bumping this to HEAD. It won't go into the current version but maybe the next. The new PHP5 date handling functions will make this much easier.

dww’s picture

Title: allow relative dates » allow relative date view filters

Changing title to avoid any potential confusion about this request with what we're talking about at #127200: Allow user to specify duration (relative) or end time (absolute).

KarenS’s picture

Status: Active » Fixed

I think the current code will do this, if I understand the issue right. You can put things like '+1 Saturday' for the next Saturday into the filter. That part of the filter is not exposed, it's just used to compute a default date.

If I misunderstood the request you can reopen.

Status: Fixed » Closed (fixed)

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