getOccurrences() 공개 메소드

Return all the occurrences in an array of \DateTime.
public getOccurrences ( ) : array
리턴 array An array of \DateTime objects
예제 #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)');
 }
예제 #2
0
 /**
  * @dataProvider variousRules
  */
 public function testVariousRules($rule, $occurrences)
 {
     $rule = new RRule($rule);
     $this->assertEquals($occurrences, $rule->getOccurrences());
     foreach ($occurrences as $date) {
         $this->assertTrue($rule->occursAt($date), 'RRule occurs at: ' . $date->format('r'));
     }
 }