1
0
mirror of https://github.com/rlanvin/php-rrule.git synced 2025-02-20 09:54:16 +01:00

Add getter methods to RSet

This commit is contained in:
rlanvin 2016-08-31 15:56:39 +03:00
parent cd3e8db2ac
commit 9b8986b954
4 changed files with 93 additions and 1 deletions

View File

@ -4,7 +4,8 @@
### Added
- Add `getRule()` method to return original rule array [#17](https://github.com/rlanvin/php-rrule/pull/17)
- Add `RRule::getRule()` method to return original rule array [#17](https://github.com/rlanvin/php-rrule/pull/17)
- Add `RSet::getRRules()`, `RSet::getExRules()`, `RSet::getDates()` and `RSet::getExDates()`
### Fixed

View File

@ -84,6 +84,18 @@ class RSet implements RRuleInterface
return $this;
}
/**
* Return the RRULE(s) contained in this set
*
* @todo check if a deep copy is needed.
*
* @return array Array of RRule
*/
public function getRRules()
{
return $this->rrules;
}
/**
* Add a RRule with exclusion rules.
* In RFC 2445 but deprecated in RFC 5545
@ -108,6 +120,18 @@ class RSet implements RRuleInterface
return $this;
}
/**
* Return the EXRULE(s) contained in this set
*
* @todo check if a deep copy is needed.
*
* @return array Array of RRule
*/
public function getExRules()
{
return $this->exrules;
}
/**
* Add a RDATE (renamed Date for simplicy, since we don't support full RDATE syntax at the moment)
*
@ -130,6 +154,18 @@ class RSet implements RRuleInterface
return $this;
}
/**
* Return the RDATE(s) contained in this set
*
* @todo check if a deep copy is needed.
*
* @return array Array of \DateTime
*/
public function getDates()
{
return $this->rdates;
}
/**
* Add a EXDATE
*
@ -152,6 +188,18 @@ class RSet implements RRuleInterface
return $this;
}
/**
* Return the EXDATE(s) contained in this set
*
* @todo check if a deep copy is needed.
*
* @return array Array of \DateTime
*/
public function getExDates()
{
return $this->exdates;
}
/**
* Clear the cache.
* Do NOT use while the class is iterating.

View File

@ -2174,7 +2174,15 @@ class RRuleTest extends PHPUnit_Framework_TestCase
$occurrences[0]->modify('+1 day');
$this->assertEquals(date_create('2007-01-02'), $occurrences[0]);
$this->assertEquals(date_create('2007-01-01'), $rrule[0], 'No modification possible with getOccurences (cached version)');
}
public function testGetRule()
{
$array = array(
'FREQ' => 'YEARLY'
);
$rrule = new RRule($array);
$this->assertInternalType('array', $rrule->getRule());
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -352,4 +352,39 @@ class RSetTest extends PHPUnit_Framework_TestCase
date_create('2016-03-21 10:00')
), $rset->getOccurrences());
}
public function testGetter()
{
$rset = new RSet();
$rset->addRRule(array(
'FREQ' => 'YEARLY',
'COUNT' => 2,
'BYDAY' => 'TU',
'DTSTART' => date_create('1997-09-02 09:00')
));
$rset->addRRule(new RRule(array(
'FREQ' => 'YEARLY',
'COUNT' => 1,
'BYDAY' => 'TH',
'DTSTART' => date_create('1997-09-02 09:00')
)));
$rset->addDate(date_create('1997-09-04 09:00'));
$rset->addDate(date_create('1997-09-05 09:00'));
$rset->addDate(date_create('1997-09-06 09:00'));
$rset->addExRule(array(
'FREQ' => 'YEARLY',
'COUNT' => 3,
'BYDAY' => 'TH',
'DTSTART' => date_create('1997-09-02 09:00')
));
$this->assertInternalType('array', $rset->getRRules());
$this->assertCount(2, $rset->getRRules());
$this->assertInternalType('array', $rset->getExRules());
$this->assertCount(1, $rset->getExRules());
$this->assertInternalType('array', $rset->getDates());
$this->assertCount(3, $rset->getDates());
$this->assertInternalType('array', $rset->getExDates());
$this->assertCount(0, $rset->getExDates());
}
}