本文整理汇总了PHP中TimeHelper::timeAgoInWords方法的典型用法代码示例。如果您正苦于以下问题:PHP TimeHelper::timeAgoInWords方法的具体用法?PHP TimeHelper::timeAgoInWords怎么用?PHP TimeHelper::timeAgoInWords使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimeHelper
的用法示例。
在下文中一共展示了TimeHelper::timeAgoInWords方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: timeAgoInWords
public function timeAgoInWords($dateTime, $options = array())
{
if (!isset($this->Asset) || !$this->settings['relativeTime']['enabled'] || isset($options['useCore'])) {
unset($options['useCore']);
return parent::timeAgoInWords($dateTime, $options);
}
if (!$this->_jsAdded) {
if ($this->settings['relativeTime']['jsPacket'] !== false) {
$this->Asset->js(array('jquery.timeago', 'jquery.mi.relativeTime'), $this->settings['relativeTime']['jsPacket']);
}
$this->_jsAdded = true;
}
$date = date('Y-m-d H:i:s O', $this->fromString($dateTime));
return String::insert($this->settings['relativeTime']['tag'], array_merge($options, compact('date')));
}
示例2: testTimeAgoInWords
/**
* Test element wrapping in timeAgoInWords
*
* @return void
*/
public function testTimeAgoInWords()
{
$Time = new TimeHelper($this->View);
$timestamp = strtotime('+8 years, +4 months +2 weeks +3 days');
$result = $Time->timeAgoInWords($timestamp, array('end' => '1 years', 'element' => 'span'));
$expected = array('span' => array('title' => $timestamp, 'class' => 'time-ago-in-words'), 'on ' . date('j/n/y', $timestamp), '/span');
$this->assertTags($result, $expected);
$result = $Time->timeAgoInWords($timestamp, array('end' => '1 years', 'element' => array('title' => 'testing', 'rel' => 'test')));
$expected = array('span' => array('title' => 'testing', 'class' => 'time-ago-in-words', 'rel' => 'test'), 'on ' . date('j/n/y', $timestamp), '/span');
$this->assertTags($result, $expected);
$timestamp = strtotime('+2 weeks');
$result = $Time->timeAgoInWords($timestamp, array('end' => '1 years', 'element' => 'div'));
$expected = array('div' => array('title' => $timestamp, 'class' => 'time-ago-in-words'), '2 weeks', '/div');
$this->assertTags($result, $expected);
}
示例3: cakeAgo
/**
* Wrapper to Time->timeAgoInWords()
* @param $var
* @return mixed
*/
function cakeAgo($var)
{
$time = new TimeHelper();
return $time->timeAgoInWords($var);
}
示例4: timeAgoInWords
/**
* Returns either a relative date or a formatted date depending
* on the difference between the current time and given datetime.
* $datetime should be in a <i>strtotime</i> - parsable format, like MySQL's datetime datatype.
*
* ### Options:
*
* - `format` => a fall back format if the relative time is longer than the duration specified by end
* - `end` => The end of relative time telling
* - `userOffset` => Users offset from GMT (in hours)
*
* Relative dates look something like this:
* 3 weeks, 4 days ago
* 15 seconds ago
*
* Default date formatting is d/m/yy e.g: on 18/2/09
*
* The returned string includes 'ago' or 'on' and assumes you'll properly add a word
* like 'Posted ' before the function output.
*
* @param string $dateString Datetime string or Unix timestamp
* @param array $options Default format if timestamp is used in $dateString
* @return string Relative time string.
* @access public
* @link http://book.cakephp.org/view/1471/Formatting
*/
function timeAgoInWords($dateTime, $options = array())
{
return parent::timeAgoInWords($dateTime, $this->__userOffset($dateTime, $options));
}