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


PHP Time::diff方法代码示例

本文整理汇总了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']);
 }
开发者ID:datalab1-com,项目名称:theme1,代码行数:53,代码来源:SessionsController.php

示例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;
 }
开发者ID:Adnan0703,项目名称:Xeta,代码行数:30,代码来源:Badges.php

示例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);
 }
开发者ID:rederlo,项目名称:cakephp,代码行数:11,代码来源:Time.php


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