當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。