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


PHP CDate::addHours方法代码示例

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


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

示例1: calcFinish

 public function calcFinish($durn, $durnType)
 {
     // since one will alter the date ($this) one better copies it to a new instance
     $f = new CDate();
     $f->copy($this);
     // get w2P time constants
     $cal_day_start = intval(w2PgetConfig('cal_day_start'));
     $cal_day_end = intval(w2PgetConfig('cal_day_end'));
     $workHours = intval(w2PgetConfig('daily_working_hours'));
     $workingDays = w2PgetConfig('cal_working_days');
     $working_days = explode(',', $workingDays);
     //temporary variables
     $inc = floor($durn);
     $hoursToAddToLastDay = 0;
     $hoursToAddToFirstDay = $durn;
     $fullWorkingDays = 0;
     $int_st_hour = $f->getHour();
     //catch the gap between the working hours and the open hours (like lunch periods)
     $workGap = $cal_day_end - $cal_day_start - $workHours;
     // calculate the number of non-working days
     $k = 7 - count($working_days);
     $durnMins = ($durn - $inc) * 60;
     if ($f->getMinute() + $durnMins >= 60) {
         $inc++;
     }
     $mins = ($f->getMinute() + $durnMins) % 60;
     if ($mins > 38) {
         $f->setMinute(45);
     } elseif ($mins > 23) {
         $f->setMinute(30);
     } elseif ($mins > 8) {
         $f->setMinute(15);
     } else {
         $f->setMinute(0);
     }
     // jump over to the first working day
     for ($i = 0; $i < $k; $i++) {
         if (array_search($f->getDayOfWeek(), $working_days) === false) {
             $f->addDays(1);
         }
     }
     if ($durnType == 24) {
         if ($f->getHour() == $cal_day_start && $f->getMinute() == 0) {
             $fullWorkingDays = ceil($inc);
             $f->setMinute(0);
         } else {
             $fullWorkingDays = ceil($inc) + 1;
         }
         // Include start day as a working day (if it is one)
         if (!(array_search($f->getDayOfWeek(), $working_days) === false)) {
             $fullWorkingDays--;
         }
         for ($i = 0; $i < $fullWorkingDays; $i++) {
             $f->addDays(1);
             if (array_search($f->getDayOfWeek(), $working_days) === false) {
                 $i--;
             }
         }
         if ($f->getHour() == $cal_day_start && $f->getMinute() == 0) {
             $f->setHour($cal_day_end);
             $f->setMinute(0);
         }
     } else {
         $hoursToAddToFirstDay = $inc;
         if ($f->getHour() + $inc > $cal_day_end - $workGap) {
             $hoursToAddToFirstDay = $cal_day_end - $workGap - $f->getHour();
         }
         if ($hoursToAddToFirstDay > $workHours) {
             $hoursToAddToFirstDay = $workHours;
         }
         $inc -= $hoursToAddToFirstDay;
         $hoursToAddToLastDay = $inc % $workHours;
         $fullWorkingDays = floor(($inc - $hoursToAddToLastDay) / $workHours);
         if ($hoursToAddToLastDay <= 0 && !($hoursToAddToFirstDay == $workHours)) {
             $f->setHour($f->getHour() + $hoursToAddToFirstDay);
         } elseif ($hoursToAddToLastDay == 0) {
             $f->setHour($f->getHour() + $hoursToAddToFirstDay + $workGap);
         } else {
             $f->setHour($cal_day_start + $hoursToAddToLastDay);
             $f->addDays(1);
         }
         if (($f->getHour() == $cal_day_end || $f->getHour() - $int_st_hour == $workHours + $workGap) && $mins > 0) {
             $f->addDays(1);
             $f->setHour($cal_day_start);
         }
         // boolean for setting later if we just found a non-working day
         // and therefore do not have to add a day in the next loop
         // (which would have caused to not respecting multiple non-working days after each other)
         $g = false;
         for ($i = 0, $i_cmp = ceil($fullWorkingDays); $i < $i_cmp; $i++) {
             if (!$g) {
                 $f->addHours(1);
             }
             $g = false;
             // calculate overriden non-working days
             if (array_search($f->getDayOfWeek(), $working_days) === false) {
                 $f->addDays(1);
                 $i--;
                 $g = true;
             }
//.........这里部分代码省略.........
开发者ID:joly,项目名称:web2project,代码行数:101,代码来源:date.class.php


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