1
0
mirror of https://github.com/rlanvin/php-rrule.git synced 2025-02-26 15:54:14 +01:00

Implement getOccurrencesBetween()

This commit is contained in:
rlanvin 2015-07-03 12:25:50 +03:00
parent b1000a4afd
commit 38df1fc962

View File

@ -155,7 +155,7 @@ class RRule implements \Iterator, \ArrayAccess, \Countable
protected $timeset = null; protected $timeset = null;
// cache variables // cache variables
public $total = null; protected $total = null;
protected $cache = array(); protected $cache = array();
// Public interface // Public interface
@ -520,8 +520,16 @@ class RRule implements \Iterator, \ArrayAccess, \Countable
*/ */
public function getOccurrencesBetween($begin, $end) public function getOccurrencesBetween($begin, $end)
{ {
$begin = self::parseDate($begin); if ( $begin !== null ) {
$end = self::parseDate($end); $begin = self::parseDate($begin);
}
if ( $end !== null ) {
$end = self::parseDate($end);
}
elseif ( ! $this->count && ! $this->until ) {
throw new \LogicException('Cannot get all occurrences of an infinite recurrence rule.');
}
$iterator = $this; $iterator = $this;
if ( $this->total !== null ) { if ( $this->total !== null ) {
@ -530,10 +538,10 @@ class RRule implements \Iterator, \ArrayAccess, \Countable
$res = array(); $res = array();
foreach ( $iterator as $occurrence ) { foreach ( $iterator as $occurrence ) {
if ( $occurrence < $begin ) { if ( $begin !== null && $occurrence < $begin ) {
continue; continue;
} }
if ( $occurrence > $end ) { if ( $end !== null && $occurrence > $end ) {
break; break;
} }
$res[] = $occurrence; $res[] = $occurrence;