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