tplaner / When

PHP Date Recursion library
https://github.com/tplaner/When
MIT License
513 stars 96 forks source link

Exceptions #62

Closed nicolasbuch closed 5 years ago

nicolasbuch commented 7 years ago

Would be nice to have a possibility to be able to define explicit exceptions in a pattern before the generation of occurrences. This could be done by datetimeobjects or even patterns. See example of use down below

Example:

// friday the 13th for the next 5 occurrences
$r = new When();
$r->startDate(new DateTime("19980213T090000"))
  ->freq("monthly")
  ->count(5)
  ->byday("fr")
  ->bymonthday(13)
  ->except([new Datetime(""), new Datetime("")])
  ->generateOccurrences();

print_r($r->occurrences);

$r->occurrences would of course return friday the 13th for the next 5 occurrences without the defined exeptions

AmritGurung commented 5 years ago

@tplaner Any progress on this issue or any workaround where we could include a list of exceptions to remove certain occurrences?

It is quite common to have a repeating event that repeats every last week of a month, and there might be cases where the event organizer may want to remove certain occurrences of the event because of some festival or reason. The only way that is possible now is, if the organizer ends the current repeating event and create a new one from the next possible week with same pattern. Manually doing this for large records is not feasible and takes a lot of time.

tplaner commented 5 years ago

I'm willing to review any PR's with this functionality.

PeterA commented 5 years ago

Thanks for adding in support for exceptions! It looks like a followup would be to extend rrule() to support the EXDATE property.