mirror of
https://github.com/rlanvin/php-rrule.git
synced 2025-02-20 09:54:16 +01:00
Keep RDATE and EXDATE ordered in RSet
This commit is contained in:
parent
0a46d7cd35
commit
c52b61f2a5
@ -80,6 +80,7 @@ class RSet implements RRuleInterface
|
||||
{
|
||||
try {
|
||||
$this->rdates[] = RRule::parseDate($date);
|
||||
sort($this->rdates);
|
||||
} catch (\Exception $e) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Failed to parse RDATE - it must be a valid date, timestamp or \DateTime object'
|
||||
@ -98,6 +99,7 @@ class RSet implements RRuleInterface
|
||||
{
|
||||
try {
|
||||
$this->exdates[] = RRule::parseDate($date);
|
||||
sort($this->exdates);
|
||||
} catch (\Exception $e) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Failed to parse EXDATE - it must be a valid date, timestamp or \DateTime object'
|
||||
|
@ -39,6 +39,19 @@ class RSetTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertFalse($rset->occursAt('1997-09-03 09:00'));
|
||||
}
|
||||
|
||||
public function testCombineRDate()
|
||||
{
|
||||
$rset =new RSet();
|
||||
$rset->addDate(date_create('1997-09-09 09:00')); // adding out of order
|
||||
$rset->addDate('1997-09-04 09:00');
|
||||
$rset->addDate('1997-09-04 09:00'); // adding a duplicate
|
||||
|
||||
$this->assertEquals(array(
|
||||
date_create('1997-09-04 09:00'),
|
||||
date_create('1997-09-09 09:00')
|
||||
), $rset->getOccurrences(), 'occurrences are ordered and deduplicated');
|
||||
}
|
||||
|
||||
public function testCombineRRuleAndDate()
|
||||
{
|
||||
$rset = new RSet();
|
||||
@ -112,7 +125,7 @@ class RSetTest extends PHPUnit_Framework_TestCase
|
||||
));
|
||||
$rset->addExdate('1997-09-04 09:00:00');
|
||||
$rset->addExdate('1997-09-11 09:00:00');
|
||||
$rset->addExdate('1997-09-18 09:00:00');
|
||||
$rset->addExdate('1997-09-18 09:00:00'); // adding out of order
|
||||
|
||||
$this->assertEquals(array(
|
||||
date_create('1997-09-02 09:00'),
|
||||
|
Loading…
x
Reference in New Issue
Block a user