simshaun / recurr

PHP library for working with recurrence rules (RRULE); meant to help with recurring calendar events.
Other
1.21k stars 136 forks source link

Skips months #6

Closed fitztrev closed 10 years ago

fitztrev commented 10 years ago

Just FYI, I recently had to roll my own recurrence library before I found yours. I was checking out yours to possibly replace the one I wrote. After looking at it, I found a few issues with calculating future dates based on a monthly recurrence.


If my start date is on the 31st, it'll skip all the months that don't have 31 days.

Input

2013-01-31
Monthly

Output

2013-01-31
2013-03-31
2013-05-31
2013-07-31
2013-08-31

Also, if my start date is the last day of its month, I would expect all monthly frequencies to also be on the last day of each subsequent month.

Input

2013-02-28
Monthly

Output

2013-03-28 - (and doesn't include the first date, like the first example did)
2013-04-28
2013-05-28
2013-06-28
2013-07-28
simshaun commented 10 years ago

I'm open for more opinions/contributions on this. For now I'm going to leave it the way it is.

fitztrev commented 10 years ago

Ok, just thought I'd share. :) I was running into the same problems while I was writing my own. Mine is for scheduling recurring payments so I had to account for these scenarios.

simshaun commented 10 years ago

I've added a configuration option that enables the behavior you are seeking for monthly recurrence. See example in the Warnings section of README.

Tagged v0.1.6

codepiper commented 10 years ago

Input

2013-01-31 Monthly Output

2013-01-31 2013-03-31 2013-05-31 2013-07-31 2013-08-31

This behavior is required in my project.

simshaun commented 10 years ago

@codepiper That is the default behavior.

brianmuse commented 8 years ago

@simshaun I think this should be reverted. iCal spec states that those months should be skipped:

Recurrence rules may generate recurrence instances with an invalid date (e.g., February 30) or nonexistent local time (e.g., 1:30 AM on a day where the local time is moved forward by an hour at 1:00 AM). Such recurrence instances MUST be ignored and MUST NOT be counted as part of the recurrence set.

And the "last day" of the month behavior is already possible through proper iCal syntax:

RRULE:FREQ=MONTHLY;INTERVAL=1;BYMONOTHDAY=-1

simshaun commented 8 years ago

It will be going away in favor of #87 when I get time. I've got a newborn, so my free time is a bit limited for a while.