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


PHP DateFormatterInterface::formatTimeDiffUntil方法代码示例

本文整理汇总了PHP中Drupal\Core\Datetime\DateFormatterInterface::formatTimeDiffUntil方法的典型用法代码示例。如果您正苦于以下问题:PHP DateFormatterInterface::formatTimeDiffUntil方法的具体用法?PHP DateFormatterInterface::formatTimeDiffUntil怎么用?PHP DateFormatterInterface::formatTimeDiffUntil使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Datetime\DateFormatterInterface的用法示例。


在下文中一共展示了DateFormatterInterface::formatTimeDiffUntil方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: formatTimestamp

 /**
  * Formats a timestamp.
  *
  * @param int $timestamp
  *   A UNIX timestamp to format.
  *
  * @return string
  *   The formatted timestamp string using the past or future format setting.
  */
 protected function formatTimestamp($timestamp)
 {
     $granularity = $this->getSetting('granularity');
     $options = ['granularity' => $granularity];
     if ($this->request->server->get('REQUEST_TIME') > $timestamp) {
         return SafeMarkup::format($this->getSetting('past_format'), ['@interval' => $this->dateFormatter->formatTimeDiffSince($timestamp, $options)]);
     } else {
         return SafeMarkup::format($this->getSetting('future_format'), ['@interval' => $this->dateFormatter->formatTimeDiffUntil($timestamp, $options)]);
     }
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:19,代码来源:TimestampAgoFormatter.php

示例2: formatTimestamp

 /**
  * Formats a timestamp.
  *
  * @param int $timestamp
  *   A UNIX timestamp to format.
  *
  * @return array
  *   The formatted timestamp string using the past or future format setting.
  */
 protected function formatTimestamp($timestamp)
 {
     $granularity = $this->getSetting('granularity');
     $options = ['granularity' => $granularity, 'return_as_object' => TRUE];
     if ($this->request->server->get('REQUEST_TIME') > $timestamp) {
         $result = $this->dateFormatter->formatTimeDiffSince($timestamp, $options);
         $build = ['#markup' => SafeMarkup::format($this->getSetting('past_format'), ['@interval' => $result->getString()])];
     } else {
         $result = $this->dateFormatter->formatTimeDiffUntil($timestamp, $options);
         $build = ['#markup' => SafeMarkup::format($this->getSetting('future_format'), ['@interval' => $result->getString()])];
     }
     CacheableMetadata::createFromObject($result)->applyTo($build);
     return $build;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:23,代码来源:TimestampAgoFormatter.php

示例3: render

 /**
  * {@inheritdoc}
  */
 public function render(ResultRow $values)
 {
     $value = $this->getValue($values);
     $format = $this->options['date_format'];
     if (in_array($format, array('custom', 'raw time ago', 'time ago', 'raw time hence', 'time hence', 'raw time span', 'time span', 'raw time span', 'inverse time span', 'time span'))) {
         $custom_format = $this->options['custom_date_format'];
     }
     if ($value) {
         $timezone = !empty($this->options['timezone']) ? $this->options['timezone'] : NULL;
         $time_diff = REQUEST_TIME - $value;
         // will be positive for a datetime in the past (ago), and negative for a datetime in the future (hence)
         switch ($format) {
             case 'raw time ago':
                 return $this->dateFormatter->formatTimeDiffSince($value, array('granularity' => is_numeric($custom_format) ? $custom_format : 2));
             case 'time ago':
                 return $this->t('%time ago', array('%time' => $this->dateFormatter->formatTimeDiffSince($value, array('granularity' => is_numeric($custom_format) ? $custom_format : 2))));
             case 'raw time hence':
                 return $this->dateFormatter->formatTimeDiffUntil($value, array('granularity' => is_numeric($custom_format) ? $custom_format : 2));
             case 'time hence':
                 return $this->t('%time hence', array('%time' => $this->dateFormatter->formatTimeDiffUntil($value, array('granularity' => is_numeric($custom_format) ? $custom_format : 2))));
             case 'raw time span':
                 return ($time_diff < 0 ? '-' : '') . $this->dateFormatter->formatTimeDiffSince($value, array('strict' => FALSE, 'granularity' => is_numeric($custom_format) ? $custom_format : 2));
             case 'inverse time span':
                 return ($time_diff > 0 ? '-' : '') . $this->dateFormatter->formatTimeDiffSince($value, array('strict' => FALSE, 'granularity' => is_numeric($custom_format) ? $custom_format : 2));
             case 'time span':
                 $time = $this->dateFormatter->formatTimeDiffSince($value, array('strict' => FALSE, 'granularity' => is_numeric($custom_format) ? $custom_format : 2));
                 return $time_diff < 0 ? $this->t('%time hence', array('%time' => $time)) : $this->t('%time ago', array('%time' => $time));
             case 'custom':
                 if ($custom_format == 'r') {
                     return format_date($value, $format, $custom_format, $timezone, 'en');
                 }
                 return format_date($value, $format, $custom_format, $timezone);
             default:
                 return format_date($value, $format, '', $timezone);
         }
     }
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:40,代码来源:Date.php


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