当前位置: 首页>>代码示例>>PHP>>正文


PHP DateFormatter::formatDiff方法代码示例

本文整理汇总了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));
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:19,代码来源:DateTest.php

示例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));
 }
开发者ID:318io,项目名称:318-io,代码行数:23,代码来源:DateTest.php


注:本文中的Drupal\Core\Datetime\DateFormatter::formatDiff方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。