本文整理汇总了PHP中DateHelper::timeSince方法的典型用法代码示例。如果您正苦于以下问题:PHP DateHelper::timeSince方法的具体用法?PHP DateHelper::timeSince怎么用?PHP DateHelper::timeSince使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateHelper
的用法示例。
在下文中一共展示了DateHelper::timeSince方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testTimeSince
public function testTimeSince()
{
Localization::changeLocale('en_US');
$minutes = 60;
$hours = $minutes * 60;
$days = $hours * 24;
// time is in the future
$future = time() + 7;
$this->assertEquals($this->object->formatDate($future, false), $this->object->timeSince($future));
// time is now
$this->assertEquals('0 seconds', $this->object->timeSince(time()));
// time is in the past (less that one year)
$this->assertEquals('7 seconds', $this->object->timeSince(time() - 7));
$this->assertEquals('3 minutes', $this->object->timeSince(time() - (3 * $minutes + 13)));
$this->assertEquals('3 minutes, 13 seconds', $this->object->timeSince(time() - (3 * $minutes + 13), true));
$this->assertEquals('4 hours', $this->object->timeSince(time() - (4 * $hours + 2 * $minutes)));
$this->assertEquals('4 hours, 1 minute', $this->object->timeSince(time() - (4 * $hours + 1 * $minutes), true));
$this->assertEquals('1 day', $this->object->timeSince(time() - (1 * $days + 1 * $minutes)));
$this->assertEquals('2 days, 2 hours', $this->object->timeSince(time() - (2 * $days + 2 * $hours), true));
$this->assertEquals('145 days', $this->object->timeSince(time() - 145 * $days));
// time is in the past (more that one year)
$this->assertEquals($this->object->formatDate(time() - 367 * $days, false), $this->object->timeSince(time() - 367 * $days));
}
示例2: testTimeSince
public function testTimeSince()
{
Localization::changeLocale("en_US");
$minutes = 60;
$hours = $minutes * 60;
$days = $hours * 24;
// time is in the future
$future = time() + 7;
$this->assertEquals($this->object->formatDate($future), $this->object->timeSince($future));
// time is now
$this->assertEquals("0 seconds", $this->object->timeSince(time()));
// time is in the past
$this->assertEquals("7 seconds", $this->object->timeSince(time() - 7));
$this->assertEquals("3 minutes", $this->object->timeSince(time() - (3 * $minutes + 13)));
$this->assertEquals("3 minutes, 13 seconds", $this->object->timeSince(time() - (3 * $minutes + 13), 1));
$this->assertEquals("4 hours", $this->object->timeSince(time() - (4 * $hours + 2 * $minutes)));
$this->assertEquals("4 hours, 1 minute", $this->object->timeSince(time() - (4 * $hours + 1 * $minutes), 1));
$this->assertEquals("1 day", $this->object->timeSince(time() - (1 * $days + 1 * $minutes)));
$this->assertEquals("2 days, 2 hours", $this->object->timeSince(time() - (2 * $days + 2 * $hours), 1));
$this->assertEquals('145 days', $this->object->timeSince(time() - 145 * $days));
$this->assertEquals($this->object->formatDate(time() - 367 * $days), $this->object->timeSince(time() - 367 * $days));
}