本文整理汇总了PHP中Drupal\Core\Datetime\DateFormatter::formatDiff方法的典型用法代码示例。如果您正苦于以下问题:PHP DateFormatter::formatDiff方法的具体用法?PHP DateFormatter::formatDiff怎么用?PHP DateFormatter::formatDiff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Datetime\DateFormatter
的用法示例。
在下文中一共展示了DateFormatter::formatDiff方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testformatDiff
/**
* Tests the formatDiff method.
*
* @dataProvider providerTestFormatDiff
*
* @covers ::formatDiff
*/
public function testformatDiff($expected, $timestamp1, $timestamp2, $options = array())
{
// Mocks a simple formatPlural implementation.
$this->stringTranslation->expects($this->any())->method('formatPlural')->with($this->anything(), $this->anything(), $this->anything(), array(), array('langcode' => isset($options['langcode']) ? $options['langcode'] : NULL))->will($this->returnCallback(function ($count, $one, $multiple) {
return $count == 1 ? $one : str_replace('@count', $count, $multiple);
}));
// Mocks a simple translate implementation.
$this->stringTranslation->expects($this->any())->method('translate')->with($this->anything())->will($this->returnCallback(function ($string, $args, $options) {
return $string;
}));
$this->assertEquals($expected, $this->dateFormatter->formatDiff($timestamp1, $timestamp2, $options));
}
示例2: testformatDiff
/**
* Tests the formatDiff method.
*
* @dataProvider providerTestFormatDiff
*
* @covers ::formatDiff
*/
public function testformatDiff($expected, $max_age, $timestamp1, $timestamp2, $options = array())
{
// Mocks a simple translateString implementation.
$this->stringTranslation->expects($this->any())->method('translateString')->willReturnCallback(function (TranslatableMarkup $arg) {
return $arg->getUntranslatedString();
});
if (isset($options['langcode'])) {
$expected_markup = new TranslatableMarkup($expected, [], ['langcode' => $options['langcode']], $this->stringTranslation);
} else {
$expected_markup = new TranslatableMarkup($expected, [], [], $this->stringTranslation);
}
$this->assertEquals($expected_markup, $this->dateFormatter->formatDiff($timestamp1, $timestamp2, $options));
$options['return_as_object'] = TRUE;
$expected_object = new FormattedDateDiff($expected, $max_age);
$this->assertEquals($expected_object, $this->dateFormatter->formatDiff($timestamp1, $timestamp2, $options));
}