Handle MONTHLY rrules with BYDAY set as the [-]5th instance of a weekday #326
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As reported in #324, requesting the 5th (or -5th) Monday/Tuesday/whatever of a month was returning erroneous dates caused by overlapping into the next (or previous) month.
There was also a related edge case, where the very last occurrence sometimes wasn't being generated. Consider the following input:
The last date generated should be the 1st of May, however running this with the parser (with the patch from #324), this date is not output.
The code essentially does this (pseudo):
After transitioning from April 3rd to May 3rd, we find that as 3rd May (
$currentdate
) is after the 2nd May ($until
) the loop exits, without generating any May occurrences for consideration.The solution given in this PR is to use a new
$untilWhile
variable that is one$frequencyInterval
(in this case one month) later along than$until
, and use that in the while loop conditional statement. (Whilst still using$until
to check each individual candidate occurrence.)Initial fix provided by @room34
Fixes #324