當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Time::timeAgoInWords方法代碼示例

本文整理匯總了PHP中Cake\I18n\Time::timeAgoInWords方法的典型用法代碼示例。如果您正苦於以下問題:PHP Time::timeAgoInWords方法的具體用法?PHP Time::timeAgoInWords怎麽用?PHP Time::timeAgoInWords使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cake\I18n\Time的用法示例。


在下文中一共展示了Time::timeAgoInWords方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: findRecent

 /**
  * Custom finder method, returns recent to-do's based on status
  *
  * @param Query $query  cakephp query object
  * @param array $options list of options
  * @return query $query cakephp query object
  */
 public function findRecent(Query $query, array $options = ['status' => 0])
 {
     return $query->where(['is_done' => $options['status']])->order(['updated' => 'DESC'])->formatResults(function ($results, $query) {
         return $results->map(function ($row) {
             $timeCreated = new Time($row->created);
             $timeUpdated = new Time($row->updated);
             $row->created = $timeCreated->timeAgoInWords();
             $row->updated = $timeUpdated->timeAgoInWords();
             $row->todo = htmlspecialchars($row->todo);
             return $row;
         });
     });
 }
開發者ID:surjit,項目名稱:todo,代碼行數:20,代碼來源:TodosTable.php

示例2: testTimeAgoInWordsNegativeValues

 /**
  * test timeAgoInWords() with negative values.
  *
  * @return void
  */
 public function testTimeAgoInWordsNegativeValues()
 {
     $time = new Time('-2 months -2 days');
     $result = $time->timeAgoInWords(['end' => '3 month']);
     $this->assertEquals('2 months, 2 days ago', $result);
     $time = new Time('-2 months -2 days');
     $result = $time->timeAgoInWords(['end' => '3 month']);
     $this->assertEquals('2 months, 2 days ago', $result);
     $time = new Time('-2 months -2 days');
     $result = $time->timeAgoInWords(['end' => '1 month', 'format' => 'yyyy-MM-dd']);
     $this->assertEquals('on ' . date('Y-m-d', strtotime('-2 months -2 days')), $result);
     $time = new Time('-2 years -5 months -2 days');
     $result = $time->timeAgoInWords(['end' => '3 years']);
     $this->assertEquals('2 years, 5 months, 2 days ago', $result);
     $time = new Time('-2 weeks -2 days');
     $result = $time->timeAgoInWords(['format' => 'yyyy-MM-dd']);
     $this->assertEquals('2 weeks, 2 days ago', $result);
     $time = new Time('-3 years -12 months');
     $result = $time->timeAgoInWords();
     $expected = 'on ' . $time->format('n/j/y');
     $this->assertEquals($expected, $result);
     $time = new Time('-1 month -1 week -6 days');
     $result = $time->timeAgoInWords(['end' => '1 year', 'accuracy' => ['month' => 'month']]);
     $this->assertEquals('1 month ago', $result);
     $time = new Time('-1 years -2 weeks -3 days');
     $result = $time->timeAgoInWords(['accuracy' => ['year' => 'year']]);
     $expected = 'on ' . $time->format('n/j/y');
     $this->assertEquals($expected, $result);
     $time = new Time('-13 months -5 days');
     $result = $time->timeAgoInWords(['end' => '2 years']);
     $this->assertEquals('1 year, 1 month, 5 days ago', $result);
     $time = new Time('-58 minutes');
     $result = $time->timeAgoInWords(['accuracy' => 'hour']);
     $this->assertEquals('about an hour ago', $result);
     $time = new Time('-23 hours');
     $result = $time->timeAgoInWords(['accuracy' => 'day']);
     $this->assertEquals('about a day ago', $result);
 }
開發者ID:RogerSchmeier,項目名稱:Webtruck,代碼行數:43,代碼來源:TimeTest.php

示例3: getPrettyDate

 /**
  * Get pretty date like "Yesterday", "2 days ago", "etc"
  *
  * @return string
  */
 public function getPrettyDate()
 {
     $time = new Time($this->_properties['updated_at']);
     return $time->timeAgoInWords(['format' => 'd']);
 }
開發者ID:martinmayer,項目名稱:notejam,代碼行數:10,代碼來源:Note.php

示例4: testTimeAgoInWordsEnd

 /**
  * test the end option for timeAgoInWords
  *
  * @dataProvider timeAgoEndProvider
  * @return void
  */
 public function testTimeAgoInWordsEnd($input, $expected, $end)
 {
     $time = new Time($input);
     $result = $time->timeAgoInWords(['end' => $end]);
     $this->assertEquals($expected, $result);
 }
開發者ID:jdaosavanh,項目名稱:clickerwebapp,代碼行數:12,代碼來源:TimeTest.php


注:本文中的Cake\I18n\Time::timeAgoInWords方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。