public function testAddYear()
 {
     $this->assertEquals(new Datum('2009-09-18'), $this->datum->addYear(1));
     $this->assertEquals(new Datum('2007-09-18'), $this->datum->addYear(-1));
     $datum = new Datum('2012-02-29');
     $this->assertEquals(new Datum('2013-02-28'), $datum->addYear(1));
     $this->assertEquals(new Datum('2016-02-29'), $datum->addYear(4));
     $this->assertEquals(new Datum('2011-02-28'), $datum->addYear(-1));
 }
Exemple #2
0
 function when($startDay, $endDay)
 {
     if ($this->exception !== false and $this->exception[1] == "1") {
         return array();
     }
     $when = array();
     $W = new stdClass();
     $W->day = $this->day;
     $W->endDay = $this->endDay;
     $W->time = $this->time;
     $when[] = $W;
     $pDay = Kalender::parseDay($this->day);
     $peDay = Kalender::parseDay($this->endDay);
     if ($peDay > $pDay) {
         $D = new Datum($pDay);
         while ($D->time() <= $peDay) {
             $newStamp = Kalender::formatDay($D->time());
             $D->addDay();
             if ($D->time() < $startDay or $D->time() > $endDay + 3600 * 25) {
                 continue;
             }
             #echo $D->time()." &lt; ".$startDay." OR ".$D->time()." &gt; ".$endDay."<br />";
             if ($newStamp == $this->day) {
                 continue;
             }
             $W = new stdClass();
             $W->day = $newStamp;
             $W->endDay = $this->endDay;
             $W->time = $this->time;
             $when[] = $W;
         }
     }
     $firstDay = Kalender::parseDay($this->day);
     if ($this->repeat) {
         switch ($this->repeatType) {
             case "daily":
                 $days = array();
                 if ($this->repeatDayOfWeek != "") {
                     $days = explode(",", $this->repeatDayOfWeek);
                     $when = array();
                     //always reset first day
                 }
                 $D = new Datum($startDay);
                 while ($D->time() <= $endDay) {
                     $newDay = Kalender::formatDay($D->time());
                     $cTime = $D->time();
                     $D->addDay();
                     #if($newDay == $this->day)
                     #s		continue;
                     if ($D->time() <= $firstDay) {
                         continue;
                     }
                     if (isset($this->exceptions[$newDay . $this->time])) {
                         continue;
                     }
                     if (!in_array(date("w", $cTime), $days)) {
                         continue;
                     }
                     $W = new stdClass();
                     $W->day = $newDay;
                     $W->endDay = $newDay;
                     $W->time = $this->time;
                     $when[] = $W;
                 }
                 break;
             case "weekly":
                 #echo Util::CLDateParser($firstDay)."<br />";
                 #echo $this->repeatInterval;
                 $weekDay = date("w", $pDay);
                 $D = new Datum($firstDay > $startDay ? $firstDay : $startDay);
                 while ($D->time() <= $endDay) {
                     if (date("w", $D->time()) == $weekDay) {
                         break;
                     }
                     $D->addDay();
                 }
                 #$counter = floor(($D->time() - $firstDay) / (3600 * 24 * 7));
                 #echo $counter."<br />";
                 while ($D->time() <= $endDay) {
                     $newDay = Kalender::formatDay($D->time());
                     if ($this->repeatUntil > 0 and $D->time() > $this->repeatUntil) {
                         break;
                     }
                     $D->addWeek(true);
                     if ($newDay == $this->day) {
                         #$counter++;
                         continue;
                     }
                     if ($this->weeks(Kalender::parseDay($this->day), $D->time()) % ($this->repeatInterval + 1) != 0) {
                         #$counter++;
                         continue;
                     }
                     if ($D->time() <= $firstDay) {
                         continue;
                     }
                     if (isset($this->exceptions[$newDay . $this->time])) {
                         continue;
                     }
                     $W = new stdClass();
                     $W->day = $newDay;
                     $W->endDay = $newDay;
                     $W->time = $this->time;
                     $when[] = $W;
                     #$counter++;
                 }
                 break;
             case "monthly":
                 $D = new Datum($startDay);
                 #echo $this->repeatWeekOfMonth;
                 if ($this->repeatWeekOfMonth > 0 and $this->repeatWeekOfMonth != 127) {
                     #$c = -1;
                     $weekDay = date("w", $pDay);
                     #if(date("d", $D->time()) > 1 AND date("d", $D->time()) < 20)
                     #$c = 0;
                     while ($D->time() <= $endDay) {
                         $newStamp = Kalender::formatDay($D->time());
                         $newDay = date("d", $D->time());
                         $newWeekDay = date("w", $D->time());
                         #if(date("d", $D->time()) == 1)
                         #	$c = 0;
                         $ts = $D->time();
                         $D->addDay();
                         #if($c < 0)
                         #	continue;
                         if ($newWeekDay != $weekDay) {
                             continue;
                         }
                         #$c++;
                         if ($newStamp == $this->day) {
                             continue;
                         }
                         #if($c != $this->repeatWeekOfMonth)
                         #	continue;
                         if (isset($this->exceptions[$newDay . $this->time])) {
                             continue;
                         }
                         if (!$this->isNth($this->repeatWeekOfMonth, $ts)) {
                             continue;
                         }
                         $W = new stdClass();
                         $W->day = $newStamp;
                         $W->endDay = $newStamp;
                         $W->time = $this->time;
                         $when[] = $W;
                     }
                 } elseif ($this->repeatWeekOfMonth == 0) {
                     $monthDay = date("d", $pDay);
                     while ($D->time() <= $endDay) {
                         $newStamp = Kalender::formatDay($D->time());
                         $newDay = date("d", $D->time());
                         $D->addDay();
                         if ($newStamp == $this->day) {
                             continue;
                         }
                         if ($newDay != $monthDay) {
                             continue;
                         }
                         if (isset($this->exceptions[$newDay . $this->time])) {
                             continue;
                         }
                         $W = new stdClass();
                         $W->day = $newStamp;
                         $W->endDay = $newStamp;
                         $W->time = $this->time;
                         $when[] = $W;
                     }
                 } elseif ($this->repeatWeekOfMonth == 127) {
                     $when = array();
                     //always reset first day
                     $monthDay = date("d", $pDay);
                     while ($D->time() <= $endDay) {
                         $newStamp = Kalender::formatDay($D->time());
                         $newDay = date("d", $D->time());
                         $maxDays = $D->getMaxDaysOfMonth();
                         $D->addDay();
                         if ($newDay != $maxDays) {
                             continue;
                         }
                         if (isset($this->exceptions[$newDay . $this->time])) {
                             continue;
                         }
                         $W = new stdClass();
                         $W->day = $newStamp;
                         $W->endDay = $newStamp;
                         $W->time = $this->time;
                         $when[] = $W;
                     }
                 }
                 break;
             case "yearly":
                 #$monthDay = date("d", Kalender::parseDay($this->day));
                 $D = new Datum(mktime(0, 1, 0, date("m", $pDay), date("d", $pDay), date("Y")));
                 #$pDay);
                 while ($D->time() <= $endDay) {
                     $newStamp = Kalender::formatDay($D->time());
                     $D->addYear();
                     if ($newStamp == $this->day) {
                         continue;
                     }
                     if (date("Y", $D->time()) <= date("Y", $endDay)) {
                         continue;
                     }
                     #echo date("Y", $D->time())." &lt; ".date("Y", $endDay)."<br />";
                     if (isset($this->exceptions[$newStamp . $this->time])) {
                         continue;
                     }
                     $W = new stdClass();
                     $W->day = $newStamp;
                     $W->endDay = $newStamp;
                     $W->time = $this->time;
                     $when[] = $W;
                 }
                 break;
         }
     }
     #echo "<pre style=\"font-size:10px;\">$this->title";
     #print_r($when);
     #echo "</pre>";
     return $when;
 }
 function __construct()
 {
     if ($this->ansicht == null) {
         $this->ansicht = "monat";
     }
     $display = mUserdata::getUDValueS("KalenderDisplay" . ucfirst($this->ansicht), "0");
     switch ($this->ansicht) {
         case "jahr":
             $Date = new Datum(Datum::parseGerDate("1.1." . date("Y")));
             for ($i = 0; $i < abs($display); $i++) {
                 if ($display > 0) {
                     $Date->addYear();
                 } else {
                     $Date->subYear();
                 }
             }
             break;
         case "monat":
             $Date = new Datum(Datum::parseGerDate("1." . date("m.Y")));
             for ($i = 0; $i < abs($display); $i++) {
                 if ($display > 0) {
                     $Date->addMonth();
                 } else {
                     $Date->subMonth();
                 }
             }
             break;
         case "woche":
             $Date = new Datum(Datum::parseGerDate(date("d.m.Y")));
             for ($i = 0; $i < abs($display); $i++) {
                 if ($display > 0) {
                     $Date->addWeek(true);
                 } else {
                     $Date->subWeek();
                 }
             }
             break;
         case "tag":
             $Date = new Datum(Datum::parseGerDate(date("d.m.Y")));
             for ($i = 0; $i < abs($display); $i++) {
                 if ($display > 0) {
                     $Date->addDay();
                 } else {
                     $Date->subDay();
                 }
             }
             break;
     }
     $this->current = clone $Date;
     if ($this->ansicht != "tag" and $this->ansicht != "jahr") {
         while (date("w", $Date->time()) > 1) {
             $Date->subDay();
         }
         if (date("w", $Date->time()) == 0) {
             $Date->addDay();
         }
     }
     $this->date = $Date;
     $this->first = $Date->time();
     $D = clone $Date;
     $rows = 5;
     if ($this->ansicht == "woche") {
         $rows = 1;
     }
     $cols = 7;
     if ($this->ansicht == "tag") {
         $cols = 1;
         $rows = 1;
     }
     if ($this->ansicht == "jahr") {
         $cols = 31;
         $rows = 12;
     }
     if ($this->ansicht != "jahr") {
         for ($i = 0; $i < $rows; $i++) {
             if ($i > 0 and date("m.Y", $D->time()) != date("m.Y", $this->current->time())) {
                 break;
             }
             for ($j = 0; $j < 7; $j++) {
                 $D->addDay();
             }
         }
         $D->subDay();
     }
     if ($this->ansicht == "jahr") {
         $D->addYear();
         $D->subDay();
     }
     $this->rows = $rows;
     $this->cols = $cols;
     $this->last = $D->time();
 }