Hi All,

I expect this is me doing something wrong, and apologies wasn't sure if this is a Views or Date issue.

I have a node with a date. I have a view (see 1.png) which shows all those nodes. Works fine. Now what I want is to display is just a week (Sun to Sat) so I add contextual filters as I have done dozens of times before (see 2.png).

This works fine with one exception. All events show, lets say all events only last 1 day, could be all day or just last 1 hour. Every combination shows, except on the last day.

So say week goes Sunday 21st Aug to Sat 27th August. 21st to 26th will show any combination but the 27th will only show events that are set to all day.

Obviously the 27th should show any event for that day the same as the rest. Done this a few times before, never had an issue, or at least never noticed it.

Forgot to say, tested on a clean website, no customisation other than content type added and views. Same issue. Have tried every combination of the date fields time zone and the sites timezone setting thinking they might be an issue, but again same issue.

So questions (1) What am I doing wrong? and (2) can anyone else reproduce?

Nick

CommentFileSizeAuthor
2.png73.99 KBnickbits
1.png80.27 KBnickbits
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nickbits created an issue. See original summary.

nickbits’s picture

So think I have figured it out and unless I am doing something really dumb that is. When I look at the query produced by this view it filters views, with the where condition, like such:

DATE_FORMAT(field_data_field_date.field_date_value2, '%Y-%m-%d %H:%i:%s') >= :node_date_argument4 AND DATE_FORMAT(field_data_field_date.field_date_value, '%Y-%m-%d %H:%i:%s') <= :node_date_argument5

Where values are

:node_date_argument4 (String, 19 characters ) 2016-08-21 00:00:00
:node_date_argument5 (String, 19 characters ) 2016-08-27 00:00:00

So this would filter values from 21st to 26th, the last value should be:

:node_date_argument5 (String, 19 characters ) 2016-08-27 23:59:59

I have created a hook to alter the query and it works a treat. But either I am being incredibly dumb or there is something broken.

Nick

nickbits’s picture

Component: Code » Date API
Category: Support request » Bug report
geffio’s picture

I had this same situation with a Calendar view we're working with. I also had to solve it using a views_query_alter, and found that the issue seems to stem from the following bit of code in the date/date_api/date_api.module file:

function date_week_range($week, $year) {
  if (variable_get('date_api_use_iso8601', FALSE)) {
    return date_iso_week_range($week, $year);
  }
  $min_date = new DateObject($year . '-01-01 00:00:00');
...
 // Move forwards to the last day of the week.
  $max_date = clone($min_date);
  date_modify($max_date, '+6 days');

As you can see, the end date is set as the start date + 6 days, but we're missing a whole 23 hours, 59 minutes, and 59 seconds there to actually span the full week. That's why our views don't include any events starting on the last day, after 00:00:00 hours. I think that last line should be replaced by

date_modify($max_date, '+6 days +23 hours +59 minutes +59 seconds');

or something to that effect.

Giovanni