fix bad test and link iCalFreq in event to get last occurrence date

master
Tanguy Pruvot 2010-10-30 19:40:16 +02:00
rodzic e03b95f43d
commit dd982d53f9
4 zmienionych plików z 50 dodań i 22 usunięć

Wyświetl plik

@ -57,27 +57,26 @@ class SG_iCal_VEvent {
unset($data['duration']);
}
//google cal set dtend as end of initial event
//google cal set dtend as end of initial event (duration)
if ( isset($this->recurrence) ) {
//if there is a recurrence rule
$until = $this->recurrence->getUntil();
$count = $this->recurrence->getCount();
//check if there is either 'until' or 'count' set
if ( $until or $count ) {
//if until is set, set that as the end date (using getTimeStamp)
if ( $until ) {
//date_default_timezone_set( xx );
$this->laststart = strtotime($until);
$this->lastend = $this->laststart + $this->getDuration();
}
if ( $until ) {
//ok..
} elseif ($count) {
//if count is set, then figure out the last occurrence and set that as the end date
$freq = new SG_iCal_Freq($this->recurrence->rrule, $start);
$until = $freq->lastOccurrence($this->start);
} else {
//forever... limit to 3 years
$this->recurrence->setUntil('+3 years');
$until = $this->recurrence->getUntil();
$this->laststart = strtotime($until);
$this->lastend = $this->laststart + $this->getDuration();
}
//date_default_timezone_set( xx ) needed ?;
$this->laststart = strtotime($until);
$this->lastend = $this->laststart + $this->getDuration();
}
$imports = array('summary','description','location');

Wyświetl plik

@ -67,11 +67,11 @@ class SG_iCal_Freq {
}
if( isset($this->rules['count']) ) {
$n = $start;
for($i=0;$i<$this->rules['count']-1;$i++) {
$n = $this->findNext($n);
$ts = $this->firstOccurrence();
for($i=1; $i<$this->rules['count']; $i++) {
$ts = $this->findNext($ts);
}
$this->rules['until'] = $n;
$this->rules['until'] = $ts;
}
}
@ -98,8 +98,17 @@ class SG_iCal_Freq {
* @return int
*/
public function nextOccurrence( $offset ) {
$start = ($offset > $this->start) ? $offset : $this->start;
return $this->findNext($start);
if ($offset < $this->start)
return $this->firstOccurrence();
return $this->findNext($offset);
}
/**
* Finds the first occurrence of the rule.
* @return int timestamp
*/
public function firstOccurrence() {
return $this->start;
}
/**
@ -107,11 +116,12 @@ class SG_iCal_Freq {
* @return int timestamp
*/
public function lastOccurrence() {
$next = $this->findNext($this->start);
$ts = $next = $this->findNext($this->start);
while ($next) {
$next = $this->findNext($next);
$ts = $next;
$next = $this->findNext($ts);
}
return $next;
return $ts;
}
/**

Wyświetl plik

@ -605,13 +605,25 @@ class FreqTest extends PHPUnit_Framework_TestCase {
}
}
public function testLastOccurrence() {
//weird : in this test $start is not an occurrence !
/*
public function testFirstOccurrenceByYearDay() {
$rule = 'FREQ=YEARLY;INTERVAL=2;BYYEARDAY=1;COUNT=5';
$start = strtotime('2009-10-27T090000');
$freq = new SG_iCal_Freq($rule, $start);
$this->assertEquals(strtotime('2018-01-01T09:00:00'), $freq->lastOccurrence());
$this->assertEquals(strtotime('2011-01-01T09:00:00'), $freq->firstOccurrence());
}
*/
public function testLastOccurrenceByYearDay() {
$rule = 'FREQ=YEARLY;INTERVAL=2;BYYEARDAY=1;COUNT=5';
$start = strtotime('2011-01-01T090000');
$freq = new SG_iCal_Freq($rule, $start);
$this->assertEquals(strtotime('2019-01-01T09:00:00'), $freq->lastOccurrence());
}
// TODO: WKST rule
private function assertRule( $rule, $start, $dateset ) {
@ -620,10 +632,11 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$n = $start - 1;
do {
$n = $freq->findNext($n);
//echo date('Y-m-d H:i:sO ',$n);
$e = (current($dateset) != -1) ? current($dateset) : false;
$this->assertEquals($e, $n);
} while( next($dateset) !== false );
}
}
?>
?>

Wyświetl plik

@ -0,0 +1,6 @@
#!/bin/sh
TIMESTAMP=$1
php -r "echo date('Y-m-d H:i:s O',$TIMESTAMP); echo \"\n\"; "