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

Handle MONTHLY rrules with BYDAY set as the [-]5th instance of a weekday #326

Merged
merged 4 commits into from
Jun 1, 2023

Conversation

s0600204
Copy link
Collaborator

@s0600204 s0600204 commented Jun 1, 2023

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:

DTSTART:20200103
RRULE:FREQ=MONTHLY;BYDAY=-5FR;UNTIL=20200502

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

$until = {RRULE UNTIL};
$currentdate = {DTSTART};

while ($currentdate <= $until) {
    generate_occurrences();
    if (any occurrences <= $until)
        add_occurrence_to_output();
    $currentdate += 1 month;
}

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

room34 and others added 3 commits May 31, 2023 02:20
Requesting the 5th (or -5th) Monday/Tuesday/whatever of a month was returning
erroneous dates caused by overlapping into the next (or previous) month.

Fixes u01jmg3#324
@u01jmg3 u01jmg3 self-requested a review June 1, 2023 12:06
@u01jmg3 u01jmg3 merged commit 44d84a3 into u01jmg3:master Jun 1, 2023
@s0600204 s0600204 deleted the issue324 branch September 11, 2023 13:24
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

Successfully merging this pull request may close these issues.

Recurrence in 5th week of month gets included in first week of next month if there is no 5th week
3 participants