I am trying to build a CarbonPeriod and CarbonInterval to return a set of occurrences. I am running into month overflow. Take the following example:
$startDate = Carbon::parse('2022-01-20');
$endDate = Carbon::parse('2022-06-14');
$separation_count = 1;
$day_of_month = 30;
$datePeriod = CarbonPeriod::create($startDate, $endDate)
->settings(['monthOverflow' => false]);
$dateInterval = CarbonInterval::months($separation_count);
if ($day_of_month) {
$datePeriod->setStartDate(
$startDate->copy()->setDay($day_of_month)
);
$dayFilter = function (Carbon $date) use ($day_of_month) {
return $date->day === $day_of_month;
};
$datePeriod->addFilter($dayFilter);
}
$datePeriod->setDateInterval($dateInterval);
return $datePeriod;
The CarbonInterval months is returning the following dates:
- 2022-01-30
I know on Carbon instances you can call addMonthNoOverflow to address this issue. How do you do it in intervals and periods?
I would like the CarbonPeriod to return
- 2022-01-30
- 2022-03-30
- 2022-04-30
- 2022-05-30