本文整理汇总了PHP中Cake\I18n\Time::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Time::add方法的具体用法?PHP Time::add怎么用?PHP Time::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\I18n\Time
的用法示例。
在下文中一共展示了Time::add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: indexToday
/**
* Index method
*
* @return void
*/
public function indexToday($dayOffset = 0)
{
$dayStart = null;
$dayEnd = null;
$this->getDay($dayOffset, $dayStart, $dayEnd, "America/Chicago");
$query = $this->Sessions->find()->where(['Sessions.created >=' => $dayStart])->where(['Sessions.created <=' => $dayEnd])->contain(['Users', 'Projects', 'Tasks'])->order(['Sessions.created' => 'DESC']);
// this is just total elapsed time for the day not a real datetime
$totalTime = new Time('2000-01-01');
//debug($totalTime);
$recs = $query->toArray();
//debug($recs);die;
$index = 0;
foreach ($recs as $session) {
$start = new Time($session['created']);
$stop = new Time($session['stopped']);
$interval = $start->diff($stop);
$totalTime->add($interval);
// if elapsed time is more than 0 days, show the day part too
if ($interval->days > 0) {
$timeLapse = $interval->format('%D:%H:%I');
} else {
$timeLapse = $interval->format('%H:%I');
}
// just show MM:SS
/* show state */
if ($session->state == 0) {
$state = "not started";
} else {
if ($session->state == 1) {
$state = "<span style='font-weight: normal;'>STARTED</span>";
} else {
if ($session->state == 2) {
$state = "stopped";
} else {
$state = "invalid";
}
}
}
$recs[$index]['timeLapse'] = $timeLapse;
$recs[$index]['totalTime'] = $totalTime->format('H:i');
$recs[$index]['stateDesc'] = $state;
$index++;
}
$this->set('sessions', $recs);
$this->set('totalTime', $totalTime);
//debug($sessions);die;
$this->set('_serialize', ['sessions']);
}