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


PHP Date::addPeriod方法代码示例

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


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

示例1: processOptimalSubperiods

 /**
  * Determine which kind of period is best to use.
  * See Range.test.php
  *
  * @param Date $startDate
  * @param Date $endDate
  */
 protected function processOptimalSubperiods($startDate, $endDate)
 {
     while ($startDate->isEarlier($endDate) || $startDate == $endDate) {
         $endOfPeriod = null;
         $month = new Month($startDate);
         $endOfMonth = $month->getDateEnd();
         $startOfMonth = $month->getDateStart();
         $year = new Year($startDate);
         $endOfYear = $year->getDateEnd();
         $startOfYear = $year->getDateStart();
         if ($startDate == $startOfYear && ($endOfYear->isEarlier($endDate) || $endOfYear == $endDate || $endOfYear->isLater($this->today)) && !($endDate->isEarlier($this->today) && $this->today->toString('Y') == $endOfYear->toString('Y') && $this->today->compareYear($endOfYear) == 0)) {
             $this->addSubperiod($year);
             $endOfPeriod = $endOfYear;
         } else {
             if ($startDate == $startOfMonth && ($endOfMonth->isEarlier($endDate) || $endOfMonth == $endDate || $endOfMonth->isLater($this->today)) && !($endDate->isEarlier($this->today) && $this->today->toString('Y') == $endOfMonth->toString('Y') && $this->today->compareMonth($endOfMonth) == 0)) {
                 $this->addSubperiod($month);
                 $endOfPeriod = $endOfMonth;
             } else {
                 // From start date,
                 //  Process end of week
                 $week = new Week($startDate);
                 $startOfWeek = $week->getDateStart();
                 $endOfWeek = $week->getDateEnd();
                 $firstDayNextMonth = $startDate->addPeriod(2, 'month')->setDay(1);
                 $useMonthsNextIteration = $firstDayNextMonth->isEarlier($endDate);
                 if ($useMonthsNextIteration && $endOfWeek->isLater($endOfMonth)) {
                     $this->fillArraySubPeriods($startDate, $endOfMonth, 'day');
                     $endOfPeriod = $endOfMonth;
                 } elseif ($this->isEndOfWeekLaterThanEndDate($endDate, $endOfWeek) && ($endOfWeek->isEarlier($this->today) || $startOfWeek->toString() != $startDate->toString() || $endDate->isEarlier($this->today))) {
                     $this->fillArraySubPeriods($startDate, $endDate, 'day');
                     break 1;
                 } elseif ($startOfWeek->isEarlier($startDate) && $endOfWeek->isEarlier($this->today)) {
                     $this->fillArraySubPeriods($startDate, $endOfWeek, 'day');
                     $endOfPeriod = $endOfWeek;
                 } else {
                     $this->addSubperiod($week);
                     $endOfPeriod = $endOfWeek;
                 }
             }
         }
         $startDate = $endOfPeriod->addDay(1);
     }
 }
开发者ID:KiwiJuicer,项目名称:handball-dachau,代码行数:50,代码来源:Range.php


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