本文整理匯總了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));
}