When using the week type with a pager, this error comes up:

Fatal error: Call to a member function modify() on boolean in /site_folder/modules/contrib/calendar/src/DateArgumentWrapper.php on line 151

It looks like it only comes up at the end of the year on the very last week (week 53) when passing between December and January of the next year. My url when I got the error was /calendar/week/201553

Comments

amahon created an issue. See original summary.

amahon’s picture

Issue summary: View changes
tedbow’s picture

@amahon thanks for reporting this. I see I hard coded 52 as the number of weeks in a year. forgot some have 53.

I will fix this. Leaving so notes here:

Need to update \Drupal\calendar\DateArgumentWrapper::validateValue

      $info = $this->getYearWeek($value);
      return $info['week'] >= 1 && $info['week'] <= 53;

checkout http://stackoverflow.com/questions/3319386/php-get-last-week-number-in-year
for possible check

tedbow’s picture

Status: Active » Fixed

Ok fixed this and committed it. Thanks for reporting it!

  • tedbow committed 9df45b6 on 8.x-1.x
    Issue #2632848 by amahon, tedbow: Fatal error: Call to a member function...
amahon’s picture

@tedbow great, works perfectly now :) thanks for the speedy fix

amahon’s picture

@tedbow with the change to fix this issue I've noticed a new problem has arisen. Now if December 31st is in the first week of the following year, the $max_week value returns as 01 so every argument in the url results in an error message saying the parameter was valid but nothing shows up in the calendar. The comment here says that in ISO-8601 specification December 28th is always in the last week of the year. If that's true then a possible solution is to simply change the line to $max_week = gmdate("W", strtotime("28 December {$info['year']}"));

amahon’s picture

Status: Fixed » Needs review
Anonymous’s picture

@amahon: the fix you propose in #7 seems to be how it is implemented now? Can you still reproduce this issue, and if yes, provide an example?

amahon’s picture

@pjonckiere in the DateArgumentWrapper.php file, line 203 is the line I'm talking about. It looks for whichever week December 31st is in but that could return as the first week of the following year. I read a comment that said the 28th will always be in the last week of the year but I'm not sure how accurate that is. Basically the problem is that if the 31st is in the first week of the next year the module thinks there is only 1 week in the year. I suggest an alternate method of figuring out the max weeks, perhaps if the result returns as 01 (being in the first week of the next year) the module checks which week the day before the first day of 01's week is in. I'm not sure if that really makes sense.

Ex.
$max_week returns as 01. The 31st is the FIRST day of week 01 so the module checks for which week the 30th is in to get the max weeks for that year.

That is just my initial thought; may or may not be best practice or ideal, just spitballing.

Anonymous’s picture

Sorry for the late reply, I'm kind of swamped at the moment.

I read a comment that said the 28th will always be in the last week of the year but I'm not sure how accurate that is.

That is the formal definition (ISO-8601), so that should be accurate. And that also means that your suggestion in #7 should resolve the issue. I looked again at the code line you mention, but it still looks to me like it is implemented that way. Can you verify that you are looking at the latest dev version? If so, can you let me now what year you have an issue with, so I can replicate it?