Problem/Motivation
When you have a view that lists stuff and use the views_date_plugin_pager plugin for pagination.
Configure "Date identifier" to "month". The plugin works and has 2 buttons previous and next...
The problem is with the next link. Date generated for it skips a month, when a 31 days are in the current month.
It's a PHP thing coming from the following lines in the plugin:
$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);
Sample script to show the issue and a fix:
$date = new DateObject('2017-03-31 23:59:59');
$date2 = clone $date;
$date3 = clone $date;
date_modify($date2, "+1 month");
date_modify($date3, "last day of next month");
echo $date,' ' , $date2, ' ', $date3;
Proposed resolution
Solution inspired from here: https://derickrethans.nl/obtaining-the-next-month-in-php.html
Will work for PHP 5.3+.
Have a designated mapping for each granularity of links that will generate the previous and next link dates.
If a mapping is missing - fallback to the current behavior.
Remaining tasks
Discussion
- Do we have a minimum version supported?
- If so, should we set it to PHP 5.3+.
- How does this reflect the fact that latest supported PHP at the moment is 5.6 (as a language).
Patch etc.
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#2 | date-date_views-date-pager-month-next-issue-2824030-D7-2.patch | 1.99 KB | ndobromirov |
Comments
Comment #2
ndobromirov CreditAttribution: ndobromirov commentedHere is a patch implementing the proposal.
The change should affect only months.
Any other granularity levels should continue to work as before.
Comment #3
lachezar.valchev CreditAttribution: lachezar.valchev as a volunteer commentedHey,
Looks good to me. I like to idea for the fallback solution.
Comment #4
happysnowmantech CreditAttribution: happysnowmantech commentedCould this be a duplicate of #2375235: Calendar block Next/Prev navigation broken? The patch that fixed that issue was included in date 7.x-2.10-rc1.
Comment #5
ndobromirov CreditAttribution: ndobromirov commentedYes it seems like duplicate.
Closing based on the already committed issue.
Reopen if deemed so.