当前位置: 首页>>代码示例>>PHP>>正文


PHP Horde_Date::diff方法代码示例

本文整理汇总了PHP中Horde_Date::diff方法的典型用法代码示例。如果您正苦于以下问题:PHP Horde_Date::diff方法的具体用法?PHP Horde_Date::diff怎么用?PHP Horde_Date::diff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Horde_Date的用法示例。


在下文中一共展示了Horde_Date::diff方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: nextRecurrence

 /**
  * Finds the next recurrence of this event that's after $afterDate.
  *
  * @param Horde_Date|string $after  Return events after this date.
  *
  * @return Horde_Date|boolean  The date of the next recurrence or false
  *                             if the event does not recur after
  *                             $afterDate.
  */
 public function nextRecurrence($after)
 {
     if (!$after instanceof Horde_Date) {
         $after = new Horde_Date($after);
     } else {
         $after = clone $after;
     }
     // Make sure $after and $this->start are in the same TZ
     $after->setTimezone($this->start->timezone);
     if ($this->start->compareDateTime($after) >= 0) {
         return clone $this->start;
     }
     if ($this->recurInterval == 0 && empty($this->rdates)) {
         return false;
     }
     switch ($this->getRecurType()) {
         case self::RECUR_DAILY:
             $diff = $this->start->diff($after);
             $recur = ceil($diff / $this->recurInterval);
             if ($this->recurCount && $recur >= $this->recurCount) {
                 return false;
             }
             $recur *= $this->recurInterval;
             $next = $this->start->add(array('day' => $recur));
             if ((!$this->hasRecurEnd() || $next->compareDateTime($this->recurEnd) <= 0) && $next->compareDateTime($after) >= 0) {
                 return $next;
             }
             break;
         case self::RECUR_WEEKLY:
             if (empty($this->recurData)) {
                 return false;
             }
             $start_week = Horde_Date_Utils::firstDayOfWeek($this->start->format('W'), $this->start->year);
             $start_week->timezone = $this->start->timezone;
             $start_week->hour = $this->start->hour;
             $start_week->min = $this->start->min;
             $start_week->sec = $this->start->sec;
             // Make sure we are not at the ISO-8601 first week of year while
             // still in month 12...OR in the ISO-8601 last week of year while
             // in month 1 and adjust the year accordingly.
             $week = $after->format('W');
             if ($week == 1 && $after->month == 12) {
                 $theYear = $after->year + 1;
             } elseif ($week >= 52 && $after->month == 1) {
                 $theYear = $after->year - 1;
             } else {
                 $theYear = $after->year;
             }
             $after_week = Horde_Date_Utils::firstDayOfWeek($week, $theYear);
             $after_week->timezone = $this->start->timezone;
             $after_week_end = clone $after_week;
             $after_week_end->mday += 7;
             $diff = $start_week->diff($after_week);
             $interval = $this->recurInterval * 7;
             $repeats = floor($diff / $interval);
             if ($diff % $interval < 7) {
                 $recur = $diff;
             } else {
                 /**
                  * If the after_week is not in the first week interval the
                  * search needs to skip ahead a complete interval. The way it is
                  * calculated here means that an event that occurs every second
                  * week on Monday and Wednesday with the event actually starting
                  * on Tuesday or Wednesday will only have one incidence in the
                  * first week.
                  */
                 $recur = $interval * ($repeats + 1);
             }
             if ($this->hasRecurCount()) {
                 $recurrences = 0;
                 /**
                  * Correct the number of recurrences by the number of events
                  * that lay between the start of the start week and the
                  * recurrence start.
                  */
                 $next = clone $start_week;
                 while ($next->compareDateTime($this->start) < 0) {
                     if ($this->recurOnDay((int) pow(2, $next->dayOfWeek()))) {
                         $recurrences--;
                     }
                     ++$next->mday;
                 }
                 if ($repeats > 0) {
                     $weekdays = $this->recurData;
                     $total_recurrences_per_week = 0;
                     while ($weekdays > 0) {
                         if ($weekdays % 2) {
                             $total_recurrences_per_week++;
                         }
                         $weekdays = ($weekdays - $weekdays % 2) / 2;
                     }
//.........这里部分代码省略.........
开发者ID:claudineyqr,项目名称:Kolab-Roundcube-Calendar,代码行数:101,代码来源:Horde_Date_Recurrence.php

示例2: getTime

 /**
  * Returns a time (max, min, avg) that tickets are in a particular state
  * (open, assigned, etc.).
  *
  * @param string $operation  One of 'max', 'min', or 'avg'.
  * @param string $state      The state to measure - 'open', etc.
  * @param string $group_by   A ticket property by which to group the
  *                           results.
  *
  * @return integer|array  The time value requested, or an array of values,
  *                        if the $group_by parameter has been specified.
  *
  * @throws Whups_Exception
  */
 public function getTime($stat, $group_by = null)
 {
     list($operation, $state) = explode('|', $stat);
     $tickets = $this->_getTicketSet('closed');
     if (!count($tickets)) {
         throw new Whups_Exception(_("There is no data for this report."));
     }
     $dataset = array();
     if (empty($group_by)) {
         $dataset[0] = array();
     }
     foreach ($tickets as $info) {
         if (is_null($info['date_resolved'])) {
             continue;
         }
         switch ($state) {
             case 'open':
                 $date1 = new Horde_Date($info['date_resolved']);
                 $diff = $date1->diff(new Horde_Date($info['timestamp']));
                 if (empty($group_by)) {
                     $dataset[0][] = $diff;
                 } else {
                     if (!isset($info[$group_by])) {
                         continue;
                     }
                     if (!isset($dataset[$info[$group_by]])) {
                         $dataset[$info[$group_by]] = array();
                     }
                     $dataset[$info[$group_by]][] = $diff;
                 }
                 break;
         }
     }
     if (!count($dataset) || is_null($group_by) && !count($dataset[0])) {
         return 'N/A';
     }
     switch ($operation) {
         case 'min':
         case 'max':
             foreach (array_keys($dataset) as $group) {
                 $dataset[$group] = $operation($dataset[$group]);
             }
             break;
         case 'avg':
             foreach (array_keys($dataset) as $group) {
                 $dataset[$group] = round(array_sum($dataset[$group]) / count($dataset[$group]), 2);
             }
             break;
     }
     if (empty($group_by)) {
         $dataset = $dataset[0];
     }
     return $dataset;
 }
开发者ID:horde,项目名称:horde,代码行数:68,代码来源:Reports.php

示例3: getDuration

 public function getDuration()
 {
     if (isset($this->_duration)) {
         return $this->_duration;
     }
     if ($this->start && $this->end) {
         $dur_day_match = $this->start->diff($this->end);
         $dur_hour_match = $this->end->hour - $this->start->hour;
         $dur_min_match = $this->end->min - $this->start->min;
         while ($dur_min_match < 0) {
             $dur_min_match += 60;
             --$dur_hour_match;
         }
         while ($dur_hour_match < 0) {
             $dur_hour_match += 24;
             --$dur_day_match;
         }
     } else {
         $dur_day_match = 0;
         $dur_hour_match = 1;
         $dur_min_match = 0;
     }
     $this->_duration = new stdClass();
     $this->_duration->day = $dur_day_match;
     $this->_duration->hour = $dur_hour_match;
     $this->_duration->min = $dur_min_match;
     $this->_duration->wholeDay = $this->isAllDay();
     return $this->_duration;
 }
开发者ID:horde,项目名称:horde,代码行数:29,代码来源:Event.php


注:本文中的Horde_Date::diff方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。