Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it me or is enableLastDayOfMonthFix not working? #182

Open
thinckx opened this issue Aug 26, 2020 · 2 comments
Open

Is it me or is enableLastDayOfMonthFix not working? #182

thinckx opened this issue Aug 26, 2020 · 2 comments

Comments

@thinckx
Copy link

thinckx commented Aug 26, 2020

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:

  • 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):

Recurr\RecurrenceCollection::__set_state(array(
   'elements' => 
[
  0  => ['date' => '2020-08-31 02:00:00.000000'],
  1  => ['date' => '2020-10-31 02:00:00.000000'],
  2  => ['date' => '2020-12-31 02:00:00.000000'],
  3  => ['date' => '2021-01-31 02:00:00.000000']
]
));

Any thoughts on what the issue could be?
Thanks!

@thinckx
Copy link
Author

thinckx commented Aug 29, 2020

For now, I've found 2 workarounds to this problem:

  1. 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.
  2. 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?

Thanks.

@stevebauman
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants