Hi. If you use Calendaer module, going to Week view, to Week 52 of 2016 year and pressing [Next >>] on pager you will notice you got Week 1 of 2017, not a Week 53 as should be.

The problem is in /date/date_views/date_views_plugin_pager.inc in function query() near line 288
in this code actually

          $this->view->date_info->prev_date = clone($argument->min_date);
          date_modify($this->view->date_info->prev_date, '-1 ' . $argument->date_handler->granularity);
          $this->view->date_info->next_date = clone($argument->max_date);
          date_modify($this->view->date_info->next_date, '+1 ' . $argument->date_handler->granularity);

... or not here ?

basically this code

$d = new DateTime('2016-12-25');
dpm($d);
$d2 = date_modify($d, '+1 ' .'week');
dpm($d2);

will give $d = '2016-12-25 00:00:00' and $d2 = '2017-01-01 00:00:00'
Which may be correct to build query
WHERE ... >$d AND ... <$d2
but the pager is wrong and week53 is not accesible throught pager

And afterthat line 98 in theme.inc gives 2017 W1

      switch ($granularity) {
        case 'week':
          $next_week = date_week(date_format($next_date, 'Y-m-d'));
          $next_arg = date_format($next_date, 'Y-\W') . date_pad($next_week);
          break;
        default:
          $next_arg = date_format($next_date, $format[$granularity]);
      }

So i did such changes starting at line 89 (below). In this case i dont have week 1 of 2017, but the days are sequence is not interrupted.

      switch ($granularity) {
        case 'week':
$c = clone $next_date;
date_modify($c, '-1 ' . 'day');
$c = date_week(date_format($c, 'Y-m-d'));
if($c > $prev_week) {
$c = clone $next_date;
date_modify($c, '-1 ' . 'day');
$next_date = $c;
} 

          $next_week = date_week(date_format($next_date, 'Y-m-d'));
          $next_arg = date_format($next_date, 'Y-\W') . date_pad($next_week);
          break;

Comments

Mykola Dolynskyi created an issue. See original summary.

Mykola Dolynskyi’s picture

Issue summary: View changes
Mykola Dolynskyi’s picture

Issue summary: View changes
Mykola Dolynskyi’s picture

Issue summary: View changes
Mykola Dolynskyi’s picture

Issue summary: View changes
d70rr3s’s picture

Actually there's no 53 week for year 2016, but you are right, the week numbers are incorrect maybe is because the module don't use ISOdate method. For example I got a site with Calendar views and it shows today (01-22-2017) week 4 in date_info property when we are in week 3 as you can see. Perhaps instead of using modify or pad we can use date_isodate_set for week granularity.

d70rr3s’s picture

After googling around (now asking the right question) I found this. In my case this is the right aproach, now date_info property of the view has the correct week number.

d70rr3s’s picture

@mykola-dolynskyi this may work for you. Now I was struggling with the same issue that you have. I have implemented an expanded pager for Calendar views instead of the regular next/prev that ships with the module. The thing is that some how the Views integration of Date API skips last week of the 2016 (I presume that is because doesn't support ISO 8601) if I navigate to 2016-W52 it gives me back the W51 week. I work around the problem reading the right date_arg instead of date_info of the view. In the other hand I'm using Carbon for date handling (awesome library!). When I read the ISO Date by default it sets on the last day so I ended with 2017-W52 instead of 2016-W52, this is easily solve by set the date on the first day of week and voilá! issue solved.

Mykola Dolynskyi’s picture

@d70rr3s thanks, i have patched the problem as described in post #0 - client is happy with this.
Carbon looks friendly.
But i have to move on other issues, thanks for paying your attention to this.

Mykola Dolynskyi’s picture

Merry Christmas and Happy new year here.
Here I am again with same "ISO-8601" bug in new place
/sites/all/modules/date/date_views/includes/date_views_argument_handler_simple.inc

  function get_default_argument($raw = FALSE) {
    ...
        $now = date_now();
        $week = date_week(date_format($now, 'Y-m-d'));
        $value = date_format($now, 'o') . '-W' . date_pad($week);
    ...
  }

instead should be

$value = date_format($now, 'Y') . '-W' . date_pad($week);

Otherwise when client opens week view of calendar (module) view this week without any params he gets 2020 year week 53 (end of next year instead of current)
Not hard to reproduce in PHP console.

mmaranao’s picture

Thanks Mykola!

lmeurs’s picture

@d70rr3s: Thank you for the tip to alter the site's regional settings!

By checking Use ISO-8601 week numbers and setting First day of week to Monday (see admin/config/regional/settings) the prev / next pager seems to work fine when navigating between years. We tested this for multiple years. No need for applying any patches! :-)