In some cases, date pager returns 2 month later in monthly view. I found it in [Calendar](https://www.drupal.org/project/calendar) module monthly view.
It seems to be derived from the fact that PHP function `date_modify()` ( which is used to calculate next month ) returns 2 months later when the number of the days of next month is smaller than the base month. e.g.
- `date_modify(new DateTime('2015-3-31'), '+1 month');` returns DateTime object with `2015-05-01 00:00:00.000000`.
- `date_modify(new DateTime('2015-1-31 23:59:59.000000'), '+1 month');` returns DateTime object with `2015-03-03 23:59:59.000000`.
Only the year and month parts are used and so the next month of `2015-01` becomes `2015-03` in this pager.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | i2580809-3.patch | 1.66 KB | jelle_s |
Comments
Comment #2
hgoto commentedHere is a patch.
And we can check this by using monthly view of Calendar module. After enabling the calendar module, we can create one calendar view from calendar view templates on `/admin/structure/views/add-template`. Thank you in advance.
Comment #3
jelle_sI made a patch that I think is a bit more robust.
date_modify($date, '+1 month')takes the '+1 month' a bit too literally. For example:If
$dateis 31 January 2015 and you add one month to it:date_modify($date, '+1 month');PHP tries to set the date to 31 February 2015, but there are only 28 days in February 2015, so the resulting date is 3 March 2015.
In this patch the pager goes to the first of next month (=> +1 day), which is 1 February 2015. Then it gets the number of days in this month (which for February 2015 is 28) and sets the date to that (28 February 2016). This will work for every month, leap year or not.
Comment #4
attiks commentedWorks like a charm
Comment #5
nikathoneI know there is a patch here but how about closing this one and mark it as a duplicate of https://www.drupal.org/node/2375235 since this one was created first.
Comment #6
echoz commentedBut is the patch in this issue "more robust" catching wider cases as described?