Exemplo n.º 1
0
 /**
  * Returns the minimum number of periods between the start of the recurrence
  * and a given time.
  * 
  * @param int $startTime Unixtime of start time
  * @param int $interval Number of days, months or years
  * @param string $type days=days, m=months, y= years 
  * @param string ceil or floor the difference.  For weekly we need to floor it because the time can fall in the week where a recurrence may take place in. 
  * @return int Number of periods that fall between event start and start time
  */
 protected function _findNumberOfDays($startTime, $interval = 1, $ceil = true)
 {
     $eventStartDateTime = new \GO\Base\Util\Date\DateTime(date('c', $this->_eventstarttime));
     $startDateTime = new \GO\Base\Util\Date\DateTime(date('c', $startTime));
     //diff is only compatible with 5.3 and we want 5.2 compatibility
     //$diff = $eventStartDateTime->diff($startDateTime, true);
     //$elapsed = $diff->days; //get the days, months or years elapsed since the event.
     $elapsed = $days = $eventStartDateTime->getDaysElapsed($startDateTime);
     $devided = $elapsed / $interval;
     $rounded = $ceil ? ceil($devided) : floor($devided);
     $periodsBetweenNextAndFirstEvent = $interval * $rounded;
     if ($ceil) {
         if ($periodsBetweenNextAndFirstEvent == $elapsed) {
             $periodsBetweenNextAndFirstEvent += $interval;
         }
     }
     return $periodsBetweenNextAndFirstEvent;
 }
Exemplo n.º 2
0
 private function _findNextCron()
 {
     $currentTime = new \GO\Base\Util\Date\DateTime();
     $findParams = \GO\Base\Db\FindParams::newInstance()->single()->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('nextrun', $currentTime->getTimestamp(), '<')->addCondition('active', true));
     return \GO\Base\Cron\CronJob::model()->find($findParams);
 }