mirror of
https://github.com/rlanvin/php-rrule.git
synced 2025-02-20 09:54:16 +01:00
parent
ea059ca381
commit
0a46d7cd35
44
src/RSet.php
44
src/RSet.php
@ -204,7 +204,49 @@ class RSet implements RRuleInterface
|
||||
|
||||
public function occursAt($date)
|
||||
{
|
||||
throw new \Exception(__METHOD__.' is unimplemented');
|
||||
$date = RRule::parseDate($date);
|
||||
|
||||
if ( in_array($date, $this->cache) ) {
|
||||
// in the cache (whether cache is complete or not)
|
||||
return true;
|
||||
}
|
||||
elseif ( $this->total !== null ) {
|
||||
// cache complete and not in cache
|
||||
return false;
|
||||
}
|
||||
|
||||
// test if it *should* occur (before exclusion)
|
||||
$occurs = false;
|
||||
foreach ( $this->rdates as $rdate ) {
|
||||
if ( $rdate == $date ) {
|
||||
$occurs = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( ! $occurs ) {
|
||||
foreach ( $this->rrules as $rrule ) {
|
||||
if ( $rrule->occursAt($date) ) {
|
||||
$occurs = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if it should occur, test if it's excluded
|
||||
if ( $occurs ) {
|
||||
foreach ( $this->exdates as $exdate ) {
|
||||
if ( $exdate == $date ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
foreach ( $this->exrules as $exrule ) {
|
||||
if ( $exrule->occursAt($date) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $occurs;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -29,6 +29,14 @@ class RSetTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals(date_create('1997-09-04 09:00'),$rset[1]);
|
||||
$this->assertEquals(array(date_create('1997-09-04 09:00')),$rset->getOccurrencesBetween('1997-09-04 00:00', '1997-09-05 00:00'));
|
||||
|
||||
$this->assertTrue($rset->occursAt('1997-09-02 09:00'));
|
||||
$this->assertFalse($rset->occursAt('1997-09-03 09:00'));
|
||||
|
||||
$rset->clearCache();
|
||||
|
||||
$this->assertTrue($rset->occursAt('1997-09-02 09:00'));
|
||||
$this->assertFalse($rset->occursAt('1997-09-03 09:00'));
|
||||
}
|
||||
|
||||
public function testCombineRRuleAndDate()
|
||||
@ -50,6 +58,14 @@ class RSetTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals(date_create('1997-09-04 09:00'),$rset[1]);
|
||||
$this->assertEquals(array(date_create('1997-09-04 09:00')),$rset->getOccurrencesBetween('1997-09-04 00:00', '1997-09-05 00:00'));
|
||||
|
||||
$this->assertTrue($rset->occursAt('1997-09-04 09:00'));
|
||||
$this->assertFalse($rset->occursAt('1997-09-03 09:00'));
|
||||
|
||||
$rset->clearCache();
|
||||
|
||||
$this->assertTrue($rset->occursAt('1997-09-04 09:00'));
|
||||
$this->assertFalse($rset->occursAt('1997-09-03 09:00'));
|
||||
}
|
||||
|
||||
public function testCombineRRuleAndExRule()
|
||||
@ -75,6 +91,14 @@ class RSetTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals(date_create('1997-09-09 09:00'),$rset[1]);
|
||||
$this->assertEquals(array(date_create('1997-09-16 09:00')),$rset->getOccurrencesBetween('1997-09-16 00:00', '1997-09-17 00:00'));
|
||||
|
||||
$this->assertTrue($rset->occursAt('1997-09-09 09:00'));
|
||||
$this->assertFalse($rset->occursAt('1997-09-04 09:00'));
|
||||
|
||||
$rset->clearCache();
|
||||
|
||||
$this->assertTrue($rset->occursAt('1997-09-09 09:00'));
|
||||
$this->assertFalse($rset->occursAt('1997-09-04 09:00'));
|
||||
}
|
||||
|
||||
public function testCombineRRuleAndExDate()
|
||||
@ -98,6 +122,14 @@ class RSetTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals(date_create('1997-09-09 09:00'),$rset[1]);
|
||||
$this->assertEquals(array(date_create('1997-09-16 09:00')),$rset->getOccurrencesBetween('1997-09-16 00:00', '1997-09-17 00:00'));
|
||||
|
||||
$this->assertTrue($rset->occursAt('1997-09-02 09:00'));
|
||||
$this->assertFalse($rset->occursAt('1997-09-04 09:00'));
|
||||
|
||||
$rset->clearCache();
|
||||
|
||||
$this->assertTrue($rset->occursAt('1997-09-02 09:00'));
|
||||
$this->assertFalse($rset->occursAt('1997-09-04 09:00'));
|
||||
}
|
||||
|
||||
public function testCombineEverything()
|
||||
|
Loading…
x
Reference in New Issue
Block a user