本文整理汇总了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;
});
});
}
示例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);
}
示例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']);
}
示例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);
}