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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ndobromirov created an issue. See original summary.

ndobromirov’s picture

Priority: Major » Normal
Status: Active » Needs review
FileSize
1.99 KB

Here is a patch implementing the proposal.
The change should affect only months.
Any other granularity levels should continue to work as before.

lachezar.valchev’s picture

Status: Needs review » Reviewed & tested by the community

Hey,

Looks good to me. I like to idea for the fallback solution.

happysnowmantech’s picture

Could 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.

ndobromirov’s picture

Status: Reviewed & tested by the community » Closed (duplicate)
Related issues: +#2375235: Calendar block Next/Prev navigation broken

Yes it seems like duplicate.
Closing based on the already committed issue.
Reopen if deemed so.