getOccurrencesBetween() public method

Return all the ocurrences after a date, before a date, or between two dates.
public getOccurrencesBetween ( mixed $begin, mixed $end ) : array
$begin mixed Can be null to return all occurrences before $end
$end mixed Can be null to return all occurrences after $begin
return array An array of \DateTime objects
Example #1
0
 public function testDateTimeMutableReferenceBug()
 {
     $date = date_create('2007-01-01');
     $rrule = new RRule(array('freq' => 'daily', 'count' => 10, 'dtstart' => $date));
     $this->assertEquals(date_create('2007-01-01'), $rrule[0]);
     $date->modify('+1day');
     $rrule->clearCache();
     $this->assertEquals(date_create('2007-01-01'), $rrule[0], 'No modification possible of dtstart');
     $rrule = new RRule(array('freq' => 'daily', 'count' => 10, 'dtstart' => '2007-01-01'));
     // offsetGet
     $this->assertEquals(date_create('2007-01-01'), $rrule[0]);
     $rrule[0]->modify('+1 day');
     $this->assertEquals(date_create('2007-01-01'), $rrule[0], 'No modification possible with offsetGet (uncached)');
     $rrule[0]->modify('+1 day');
     $this->assertEquals(date_create('2007-01-01'), $rrule[0], 'No modification possible with offsetGet (cached)');
     // iterate
     $rrule->clearCache();
     foreach ($rrule as $occurrence) {
         break;
     }
     $this->assertEquals(date_create('2007-01-01'), $occurrence);
     $occurrence->modify('+1 day');
     $this->assertEquals(date_create('2007-01-01'), $rrule[0], 'No modification possible with foreach (uncached)');
     foreach ($rrule as $occurrence) {
         break;
     }
     $this->assertEquals(date_create('2007-01-01'), $occurrence);
     $occurrence->modify('+1 day');
     $this->assertEquals(date_create('2007-01-01'), $rrule[0], 'No modification possible with foreach (cached)');
     // getOccurences
     $occurrences = $rrule->getOccurrences();
     $this->assertEquals(date_create('2007-01-01'), $occurrences[0]);
     $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 (uncached version)');
     $occurrences = $rrule->getOccurrences();
     $this->assertEquals(date_create('2007-01-01'), $occurrences[0]);
     $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)');
     // getOccurrencesBetween
     $occurrences = $rrule->getOccurrencesBetween(null, null);
     $this->assertEquals(date_create('2007-01-01'), $occurrences[0]);
     $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 (uncached version)');
     $occurrences = $rrule->getOccurrencesBetween(null, null);
     $this->assertEquals(date_create('2007-01-01'), $occurrences[0]);
     $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)');
 }