rlanvin / php-rrule

Lightweight and fast recurring dates library for PHP (RFC 5545)
Other
601 stars 83 forks source link

addExDate is not correct #35

Closed coffeduong closed 7 years ago

coffeduong commented 7 years ago

I follow the example here https://github.com/rlanvin/php-rrule/wiki/RSet#iteration But I think it should be like this

use RRule\RSet;

$rset = new RSet;
$rset->addRRule([
    'freq' => RRule::DAILY,
    'interval' => 2,
    'count' => 5,
    'dtstart' => '1997-09-02 09:00:00'
]);
$rset->addExDate('1997-09-06 09:00:00');

foreach ( $rset as $occurrence ) {
    echo $occurrence->format('r'),"\n";
}

// output:
// Tue, 02 Sep 1997 09:00:00 +0000
// Thu, 04 Sep 1997 09:00:00 +0000
// (Sat, 06 Sep 1997 09:00:00 +0000 will not be outputed because it is in EXDATE)
// Mon, 08 Sep 1997 09:00:00 +0000
// Wed, 10 Sep 1997 09:00:00 +0000
// Fri, 12 Sep 1997 09:00:00 +0000

Because we have count = 5, if 06 Sep 1997 is remove, 12 Sep 1997 should add in the end. In your example you only show 4 occurrences. I think it doesn't make sense :)

rlanvin commented 7 years ago

I think it doesn't make sense :)

Well, I understand your point, but this is how the RFC has been specified, and how a recurrence set works. The COUNT applies to the RRULE only, not the entire set.

To make things clearer, here are some examples:

If you want the behavior you are describing, I suggest you remove the COUNT altogether and instead select only the first 5 occurrences (use getOccurrences(5) for example).

I hope this makes sense to you now.

coffeduong commented 7 years ago

This make sense now :) Thank you very much!