You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A monthly recurring instance without end date, happening each 31st of the month. Return all instances in period between now (2020-08-26) and 1st of march 2021:
PHP 7.3.19
MySQL 5.7.29
"simshaun/recurr": "^4.0"
use Recurr\Rule;
use Carbon\Carbon;
use Recurr\Transformer\ArrayTransformer;
use Recurr\Transformer\ArrayTransformerConfig;
$rrule = "FREQ=MONTHLY;BYMONTHDAY=31;INTERVAL=1";
$recur_start_at = "2020-08-19 02:00:00";
$recur_end_at = null;
$start = Carbon::now();
$end = Carbon::parse("2021-03-01 02:00:00");
When
We want to make sure it happens every month, also in months with less than 31 days, setting it on the last day of each month. Following the docs, it should be fixed like this:
$rule = (new Rule($rrule, Carbon::parse($recur_start_at)))->setUntil($end);
$transformer = new ArrayTransformer();
$transformerConfig = new ArrayTransformerConfig();
$transformerConfig->enableLastDayOfMonthFix();
$transformer->setConfig($transformerConfig);
$transformed = $transformer->transform($rule);
print_r($transformed);
Then
I would expect to count 7 instances, but only receiving 4. Unfortunately, the output does not include September, November & February (output is shortened):
For now, I've found 2 workarounds to this problem:
Set $recur_start_at to "2020-08-31" (the first moment the instance should occur) AND remove BYMONTHDAY=31; from the recur string. This sets $implicitByMonthDay to true, which triggers the fixLastDayOfMonth logic.
Change the string to use FREQ=MONTHLY;BYMONTHDAY=-1;INTERVAL=1, which also triggers the fix.
Considering I seem to be the only one asking about this issue, could this mean that my initial approach on storing the string in combination with the start date is wrong? And if so, what's the correct way to store it?
I'm having this exact issue as well. Library seems to have been abandoned though 😭
I'm personally going with your 2nd solution @thinckx, but I'm just surgically replacing BYMONTHDAY={29,30,31} with BYMONTHDAY=-1 in the Rule before generating occurrences when necessary.
Given:
A monthly recurring instance without end date, happening each 31st of the month. Return all instances in period between now (2020-08-26) and 1st of march 2021:
When
We want to make sure it happens every month, also in months with less than 31 days, setting it on the last day of each month. Following the docs, it should be fixed like this:
Then
I would expect to count 7 instances, but only receiving 4. Unfortunately, the output does not include September, November & February (output is shortened):
Any thoughts on what the issue could be?
Thanks!
The text was updated successfully, but these errors were encountered: