occursAt() public method

This method will attempt to determine the result programmatically. However depending on the BYXXX rule parts that have been set, it might not always be possible. As a last resort, this method will loop through all occurrences until $date. This will incurr some performance penalty.
public occursAt ( mixed $date ) : boolean
$date mixed
return boolean
Esempio n. 1
0
 public function testOccursAtTakeTimezoneIntoAccount()
 {
     $rrule = new RRule(array('freq' => 'daily', 'count' => 365, 'dtstart' => date_create('2015-07-01 09:00:00')));
     $this->assertTrue($rrule->occursAt('2015-07-02 09:00:00'), 'When timezone is not specified, it takes the default timezone');
     $rrule = new RRule(array('freq' => 'daily', 'count' => 365, 'dtstart' => date_create('2015-07-01 09:00:00', new DateTimeZone('Australia/Sydney'))));
     $this->assertTrue($rrule->occursAt(date_create('2015-07-02 09:00:00', new DateTimeZone('Australia/Sydney'))));
     $this->assertTrue($rrule->occursAt(date_create('2015-07-01 23:00:00', new DateTimeZone('UTC'))), 'Timezone is converted for comparison (cached)');
     $rrule->clearCache();
     $this->assertTrue($rrule->occursAt(date_create('2015-07-01 23:00:00', new DateTimeZone('UTC'))), 'Timezone is converted for comparison (uncached)');
     $rrule->clearCache();
     $this->assertFalse($rrule->occursAt('2015-07-02 09:00:00'), 'When passed a string, default timezone is used for creating the DateTime');
     $rrule->clearCache();
     $this->assertTrue($rrule->occursAt('Wed, 01 Jul 2015 09:00:00 +1000'), 'When passed a string with timezone, timezone is kept (uncached)');
     $this->assertTrue($rrule->occursAt('Wed, 01 Jul 2015 09:00:00 +1000'), 'When passed a string with timezone, timezone is kept (cached)');
     $rrule->clearCache();
     $this->assertTrue($rrule->occursAt('2015-07-01T09:00:00+10:00'), 'When passed a string with timezone, timezone is kept (uncached)');
     $this->assertTrue($rrule->occursAt('2015-07-01T09:00:00+10:00'), 'When passed a string with timezone, timezone is kept (cached)');
     // test with DST
     $rrule = new RRule(array('freq' => 'daily', 'count' => 365, 'dtstart' => date_create('2015-07-01 09:00:00', new DateTimeZone('Europe/Helsinki'))));
     $this->assertTrue($rrule->occursAt(date_create('2015-07-02 09:00:00', new DateTimeZone('Europe/Helsinki'))));
     $this->assertTrue($rrule->occursAt(date_create('2015-07-02 06:00:00', new DateTimeZone('UTC'))), 'During summer time, Europe/Helsinki is UTC+3 (cached)');
     $rrule->clearCache();
     $this->assertTrue($rrule->occursAt(date_create('2015-07-02 06:00:00', new DateTimeZone('UTC'))), 'During summer time, Europe/Helsinki is UTC+3 (uncached)');
     $this->assertTrue($rrule->occursAt(date_create('2015-12-02 09:00:00', new DateTimeZone('Europe/Helsinki'))));
     $this->assertTrue($rrule->occursAt(date_create('2015-12-02 07:00:00', new DateTimeZone('UTC'))), 'During winter time, Europe/Helsinki is UTC+2 (cached)');
     $rrule->clearCache();
     $this->assertTrue($rrule->occursAt(date_create('2015-12-02 07:00:00', new DateTimeZone('UTC'))), 'During winter time, Europe/Helsinki is UTC+2 (uncached)');
 }
Esempio n. 2
0
 /**
  * @dataProvider notOccurrences
  */
 public function testNotOccurrences($rule, $not_occurences)
 {
     $rule = new RRule($rule);
     foreach ($not_occurences as $date) {
         $this->assertFalse($rule->occursAt($date), "Rule must not match {$date}");
     }
 }