本文整理汇总了PHP中Cake\I18n\Time::diff方法的典型用法代码示例。如果您正苦于以下问题:PHP Time::diff方法的具体用法?PHP Time::diff怎么用?PHP Time::diff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\I18n\Time
的用法示例。
在下文中一共展示了Time::diff方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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']);
}
示例2: registerBadge
/**
* Unlock all badges related to comments.
*
* @param \Cake\Event\Event $event The Model.BlogArticlesComments.add event that was fired.
*
* @return bool
*/
public function registerBadge(Event $event)
{
$this->Badges = TableRegistry::get('Badges');
if (!$event->data['user'] instanceof User) {
return false;
}
$badges = $this->Badges->find('all')->select(['id', 'name', 'picture', 'rule'])->where(['type' => 'registration'])->hydrate(false)->toArray();
if (empty($badges)) {
return true;
}
$this->Users = TableRegistry::get('Users');
$userId = $event->data['user']->id;
$user = $this->Users->find()->where(['id' => $userId])->select(['created'])->first();
$today = new Time();
$created = $user->created;
$diff = $today->diff($created)->y;
foreach ($badges as $badge) {
if ($diff >= $badge['rule']) {
$this->_unlockBadge($badge, $userId);
}
}
return true;
}
示例3: fromNow
/**
* Convenience method for getting the remaining time from a given time.
*
* @param \DateTime|\DateTimeImmutable $datetime The date to get the remaining time from.
* @return \DateInterval|bool The DateInterval object representing the difference between the two dates or FALSE on failure.
*/
public static function fromNow($datetime)
{
$timeNow = new Time();
return $timeNow->diff($datetime);
}