当前位置: 首页>>代码示例>>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;未经允许,请勿转载。