The views pager constructed in date_views/theme/theme.inc makes incorrect assumptions for the "next week" link.
This causes problems where your week view will jump from December 2012 to January 2012 when pressing next.
This is the case because 2013 starts on a tuesday.. It will calculate the next weeknumber ( = 1) and the month is derived from the first day of the next week (2012)

I have implemented a small fix, it's not really elegant but it works for me.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bluetegu’s picture

Thanks. Included is a patch that fixes the pager issue using a different approach, and also fixes the default 'current date' value for views. The patch replaces 'regular' year with ISO year to match the ISO week used.

rv0’s picture

@bluetegu
I'm not sure if you can assume ISO week numbers, as thats a setting in the backend? Your patch does look a lot more elegant.

also, I don't know why the testbot isn't testing our patches?

bluetegu’s picture

date('W') is ISO week, hence we need date('o') for ISO year. Prior to patch, we get 01 for week and 2012 for year. After patch we get 2013 for year and 01 for week, as should. I'm still hoping the testbot will do its thing.

bluetegu’s picture

Another fix: the default week value doesn't pad the week number, e.g. produce W02 rather W2 which is wrong. Here is the updated patch.

Status: Needs review » Needs work

The last submitted patch, week_contextual_filter_default_2013-5.patch, failed testing.

brockfanning’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
1.48 KB

As the end of the year nears, it looks like this bug is rearing its ugly head again. Here is a compilation and re-roll of the work done by bluetegu so far.

vijaycs85’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the patch @brockfanning & @bluetegu.

+++ b/date_views/theme/theme.inc
@@ -75,8 +75,8 @@ function template_preprocess_date_views_pager(&$vars) {
+        $next_arg = date_format($next_date, 'o-\W') . date_pad($next_week);
+        $prev_arg = date_format($prev_date, 'o-\W') . date_pad($prev_week);

+++ b/date_views/includes/date_views_argument_handler_simple.inc
@@ -64,7 +64,7 @@ class date_views_argument_handler_simple extends views_handler_argument_date {
+        $value = date_format($now, 'o') . '-W' . date_pad($week);

Nice, fix. So 'o' is - ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0)

Looks good to me.

podarok’s picture

Status: Reviewed & tested by the community » Fixed

#6 commited to dev
Thanks!

  • Commit dfcaf74 on 7.x-2.x authored by brockfanning, committed by podarok:
    Issue #1874422 by bluetegu, brockfanning, rv0: Fixed Week pager may...

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Hello i installed patch #6 and it seemed to work. But now im getting problems in year 2016 when using next week. Next is linking to the week which is actual showing.

danwonac’s picture

I'm experiencing similar issues with the latest dev version paging forward and backward weeks with block views between 2014 and 2015.

The issue appears to be with how the previous/next arguments are generated. The ISO week number for 29th-31st December 2014 is 1 (as is returned by date_week()) however the argument is created using date_format($date, 'Y-\W') which for any of these particular dates is of course 2014.

Hence, paging from week 52 of 2014 to the next week generates the argument ?mini=2014-W01 and paging from week 2 of 2015 to the previous week generates the argument ?mini=2014-W01 (because the date is of course the same, December 29th 2014).

I've modified date\date_views\theme.inc to test the year and week. If the month is December but the week is 1, add 1 to the year:

$prev_week = date_week(date_format($prev_date, 'Y-m-d'));
$prev_year = (date_format($prev_date, 'n') == 12 && $prev_week == 1) ? date_format($prev_date, 'Y') + 1 : date_format($prev_date, 'Y');
$prev_arg = $prev_year . '-W' . date_pad($prev_week);

$next_week = date_week(date_format($next_date, 'Y-m-d'));
$next_year = (date_format($next_date, 'n') == 12 && $next_week == 1) ? date_format($next_date, 'Y') + 1 : date_format($next_date, 'Y');
$next_arg = $next_year . '-W' . date_pad($next_week);

This has fixed it for me.

Alas, haven't quite figured out how to make a patch yet but should be close.

danwonac’s picture

Here's a better patch for #12.

danwonac’s picture

Hmm, the previous week pager doesn't seem to be working either. This looks like it is because there is no granularity specified when getting the previous and next dates when skip_empty_ages is empty:

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

Rolled another patch to incorporate #12 and this too.

shortspoken’s picture

Thanks! #14 fixed it for me!

BBC’s picture

I'm not using ISO-8601 week numbers on my site and found that the changes in #6 actually created the problem this issue was intended to solve.

In my case, hitting next when viewing the last week of the year caused the view to jump to the following year. In other words, selecting the next week button on December 22, 2014 was taking users to December 28, 2015 rather than to December 29, 2014.

I tried the patches in #12-14 here and they didn't help. Looking back at #6, I found that reverting the changes to theme.inc (using Y-\W instead of 0-\W) got the previous and next buttons working as expected again.

Anonymous’s picture

#14 is still not working for me. 2016ff still causing problem when using week pager on a view. The next button does not change the week, it loads every time the actual showing week. Can someone confirm and reopen this?
Best regards, Edin

danwonac’s picture

The latest dev version is working for me with patch from Undefined variable: granularity in date_views_plugin_pager->query()

schifazl’s picture

I confirm what danwonac said in #18, dev version + the other patch works flawlessly!

nikita.izotov’s picture

Problem
I have by week pager, so when i click to the 2015-W53 and then next it jumps to 2016-W02, so the first week is gone. and later all that year it counting weeks from 2nd. Nothing bad, just simple drupal numbers, but... i have this issue on calendar and since that is happening i've lost some events

Selecting 23.02.2016 on calendar (it is in the8th week of 2016) shows 2016-W08 in pager link and Week of Monday, February 15, 2016. So as calendar show 15.02.2016 belongs to 7th week, not to 8th what i was selected.

jlea9378’s picture

Status: Closed (fixed) » Needs work

I tried patch #14 with the latest dev release of Date and it didn't work flawlessly for me. Clicking the Next button in the year view jumps me from January to March! What happened to Feb?? If I click Next again, it skips April and jumps me to May! And so on down the line... but if I click Prev I can get to the skipped months. The week view is working similarly, skipping weeks when clicking Next. The day and year views work fine -- no skipping.

Using:
Calendar 7.x-3.5
Date 7.x-2.9-beta2+2-dev (2015-Jan-05)

Anonymous’s picture

i can confirm #20 too.
i used latest dev + #12. i also found that if u set Use ISO-8601 week numbers in 2016, prev button is jumping two weeks back and next ist linking to the active week.

danwonac’s picture

My use case is with php v5.3.29, regional settings using ISO-8601 week numbers and latest dev version.

I have found that the next pager from 2015-W53 is not working correctly.

In the date_api.module, the function date_iso_week_range() appears to fail under the specific circumstance that the 28th of December is a Monday (just like 2015). date_modify() attempts to add one Monday to the date but the function doesn't add a week if the day is already a Monday (at least in the version of php I'm running (5.3.29).

date_modify($min_date, '+1 Monday'); // Fails to add a week when $min_date is already a Monday

This means that the incorrect date is returned for the range for all dates of the next year. I've no idea whether this occurs on other versions of php but ensuring a Monday is added is necessary which I did with

date_modify($min_date, '+1 Sunday'); 
date_modify($min_date, '+1 Monday');

Two related issues are also required to fix this:
Patch #35 from Calendar block Next/Prev navigation broken

@brockfanning's patch #6 of this issue has been partially applied to the latest dev version, the fix in date_views_argument_handler_simple.inc is there. The other fixes to theme.inc and are not applied but still required. The code changed a bit in the latest dev version where this was previously applied.

I've rolled these all into one attached patch.

I've tested this with a view paging back and forth for 2013, 2014, 2015 and 2016 and it all works as expected.

I suspect the date_modify() issue will fix @edin.dedagic's issue with jumping two weeks back and no weeks forward, it's the same symptom of the 1st week of the year being a week behind what it should be. Similarly #20 from @nikita.izotov.

Anonymous’s picture

#23 worked for me!!

aharris6’s picture

#23 worked for me as well

rv0’s picture

#23 is working great

This line should be removed from patch though:

-  // Jump ahead to the desired week for the beginning of the week range.
+  // Jump ahead to the desired week for the beginning of the week range
cafuego’s picture

I've just applied a pager patch from #2375235: Calendar block Next/Prev navigation broken which touches part of the code that's also in the patch on comment #23 in this issue.

Can you check whether the issue still exists on the latest 7.x-2.x module? If so, this patch will need a reroll to make it apply again.

coredumperror’s picture

Updating the latest dev release (2015-Dec-10) fixed this pager issue for me, without any patches from this thread.

BBC’s picture

This problem resurfaced for me again this year. The 2015-Dec-10 7.x-2.x-dev release works for me as well and the issues with ISO-8601 week numbers described in #16 seem to be resolved. Thanks!

Peter Arius’s picture

Sorry, I can't confirm that this is fixed in latest dev.

date 7.x-2.9+5-dev (2015-Dez-10)
calendar 7.x-3.5

Steps to reproduce:

* show calendar month view, December 2015
* switch to week view (Week of Dec 28, 2015), OK
* next link goes to 2016-W01 (OK)
* click on next link -> URL is .../2016-W01 (OK), but still 2015-W53 is displayed (wrong)

When I enter any URL .../2016-Wnn, the view shows week nn-1. The previous link goes to 2016-W(nn-2) and the next link to 2016-Wnn, so the week view and pager is effectively unusable.

However, patch #2 from #2416421-2: Wrong week numbering for 2016 solves the issue for me.

StryKaizer’s picture

Happy new year everybody who's just like me, visitting this issue ;)

Patch in #23 worked for me, might need a reroll though (manual apply fixxed the issue).

SeanA’s picture

Title: Week pager may cause incorrect "next" link on year change » Pager may cause incorrect "prev" or "next" link
SeanA’s picture

SeanA’s picture

dsoms’s picture

#23 worked fine for me with Date 7.x-2.9

Thank you very much ;-)

Stephen Ollman’s picture

#23 fixed my issue with not being able to access 'Next' week.

sobi3ch’s picture

Status: Needs review » Reviewed & tested by the community

#34 works like a charm :)

The last submitted patch, 23: week-pager-next-prev-year-fix-1874422-23.patch, failed testing.

SeanA’s picture

danwonac gets credit for sorting it all out. =)

podarok’s picture

Status: Reviewed & tested by the community » Fixed

#34 merged. Thanks.

  • podarok committed e29ef15 on 7.x-2.x authored by SeanA
    Issue #1874422 by danwonac, bluetegu, SeanA, rv0, brockfanning: Pager...

Status: Fixed » Closed (fixed)

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