本文整理汇总了PHP中CDate::setHour方法的典型用法代码示例。如果您正苦于以下问题:PHP CDate::setHour方法的具体用法?PHP CDate::setHour怎么用?PHP CDate::setHour使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDate
的用法示例。
在下文中一共展示了CDate::setHour方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
//.........这里部分代码省略.........
示例2: check
public function check()
{
// ensure changes to check boxes and select lists are honoured
$this->event_private = intval($this->event_private);
$this->event_type = intval($this->event_type);
$this->event_cwd = intval($this->event_cwd);
//If the event recurs then set the end date day to be equal to the start date day and keep the hour:minute of the end date
//so that the event starts recurring from the start day onwards n times after the start date for the period given
//Meaning: The event end date day is useless as far as recurring events are concerned.
if ($this->event_recurs) {
$start_date = new CDate($this->event_start_date);
$end_date = new CDate($this->event_end_date);
$hour = $end_date->getHour();
$minute = $end_date->getMinute();
$end_date->setDate($start_date->getDate());
$end_date->setHour($hour);
$end_date->setMinute($minute);
$this->event_end_date = $end_date->format(FMT_DATETIME_MYSQL);
}
return null;
}