コード例 #1
0
ファイル: Date.php プロジェクト: ulrikkold/cal
 /**
  * Gets number of days in the month for this date
  *
  * Gets number of days in the month for this date
  *
  * @access public
  * @return int number of days in this month
  */
 function getDaysInMonth()
 {
     return Calc::daysInMonth($this->month, $this->year);
 }
コード例 #2
0
ファイル: DateParser.php プロジェクト: ulrikkold/cal
 function evaluateRange(&$date, $range, $rangeValue)
 {
     if (!is_numeric($range)) {
         if ($range == 'last') {
             $range = -1;
         } else {
             if ($range == 'next') {
                 $range = 1;
             }
         }
     }
     if (is_numeric($rangeValue)) {
         $date->addSeconds($rangeValue * $range);
     } else {
         if (is_array($rangeValue)) {
             foreach ($rangeValue as $key => $value) {
                 if ($key == 'weekday' && $range > 0) {
                     for ($i = 0; $i < $range; $i++) {
                         $formatedDate = Calc::nextDayOfWeek($value, $date->getDay(), $date->getMonth(), $date->getYear());
                         $date = new \TYPO3\CMS\Cal\Model\CalDate($formatedDate);
                         $date->setTZbyId('UTC');
                     }
                 } else {
                     if ($key == 'weekday' && $range < 0) {
                         for ($i = 0; $i > $range; $i--) {
                             $formatedDate = Calc::prevDayOfWeek($value, $date->getDay(), $date->getMonth(), $date->getYear());
                             $date = new \TYPO3\CMS\Cal\Model\CalDate($formatedDate);
                             $date->setTZbyId('UTC');
                         }
                     } else {
                         if ($value == 'week' && $range > 0) {
                             $date->addSeconds($range * 604800);
                         } else {
                             if ($value == 'week' && $range < 0) {
                                 $date->subtractSeconds($range * 604800);
                             }
                         }
                     }
                 }
             }
         } else {
             if ($range > 0) {
                 if ($rangeValue == 'month') {
                     for ($i = 0; $i < $range; $i++) {
                         $days = Calc::daysInMonth($date->getMonth(), $date->getYear());
                         $endOfNextMonth = new \TYPO3\CMS\Cal\Model\CalDate(Calc::endOfNextMonth($date->getDay(), $date->getMonth(), $date->getYear()));
                         $date->addSeconds(60 * 60 * 24 * $days);
                         if ($date->after($endOfNextMonth)) {
                             $date->setDay($endOfNextMonth->getDay());
                             $date->setMonth($endOfNextMonth->getMonth());
                             $date->setYear($endOfNextMonth->getYear());
                         }
                     }
                 } else {
                     if ($rangeValue == 'year') {
                         $date->setYear($date->getYear() + $range);
                     } else {
                         if ($rangeValue == 'hour') {
                             $date->addSeconds($range * 3600);
                         } else {
                             if ($rangeValue == 'minute') {
                                 $date->addSeconds($range * 60);
                             } else {
                                 $date->addSeconds($range * 86400);
                             }
                         }
                     }
                 }
             } else {
                 if ($range < 0) {
                     if ($rangeValue == 'month') {
                         for ($i = 0; $i > $range; $i--) {
                             $endOfPrevMonth = new \TYPO3\CMS\Cal\Model\CalDate(Calc::endOfPrevMonth($date->getDay(), $date->getMonth(), $date->getYear()));
                             $days = Calc::daysInMonth($endOfPrevMonth->getMonth(), $endOfPrevMonth->getYear());
                             $date->subtractSeconds(60 * 60 * 24 * $days);
                         }
                     } else {
                         if ($rangeValue == 'year') {
                             $date->setYear($date->getYear() - abs($range));
                         } else {
                             if ($rangeValue == 'hour') {
                                 $date->subtractSeconds(abs($range) * 3600);
                             } else {
                                 if ($rangeValue == 'minute') {
                                     $date->subtractSeconds(abs($range) * 60);
                                 } else {
                                     $date->subtractSeconds(abs($range) * 86400);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $date->subtractSeconds(1);
 }