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


PHP DateFormatterInterface::formatTimeDiffSince方法代码示例

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


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

示例1: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form['description'] = array('#markup' => '<p>' . t('Cron takes care of running periodic tasks like checking for updates and indexing content for search.') . '</p>');
     $form['run'] = array('#type' => 'submit', '#value' => t('Run cron'));
     $status = '<p>' . $this->t('Last run: %time ago.', array('%time' => $this->dateFormatter->formatTimeDiffSince($this->state->get('system.cron_last')))) . '</p>';
     $form['status'] = array('#markup' => $status);
     $cron_url = $this->url('system.cron', array('key' => $this->state->get('system.cron_key')), array('absolute' => TRUE));
     $form['cron_url'] = array('#markup' => '<p>' . t('To run cron from outside the site, go to <a href=":cron">@cron</a>', array(':cron' => $cron_url, '@cron' => $cron_url)) . '</p>');
     if (!$this->moduleHandler->moduleExists('automated_cron')) {
         $form['cron'] = array('#markup' => $this->t('Enable the <em>Automated Cron</em> module to allow cron execution at the end of a server response.'));
     }
     return $form;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:16,代码来源:CronForm.php

示例2: buildRow

 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $row['username']['data'] = array('#theme' => 'username', '#account' => $entity);
     $row['status'] = $entity->isActive() ? $this->t('active') : $this->t('blocked');
     $roles = user_role_names(TRUE);
     unset($roles[RoleInterface::AUTHENTICATED_ID]);
     $users_roles = array();
     foreach ($entity->getRoles() as $role) {
         if (isset($roles[$role])) {
             $users_roles[] = $roles[$role];
         }
     }
     asort($users_roles);
     $row['roles']['data'] = array('#theme' => 'item_list', '#items' => $users_roles);
     $options = ['return_as_object' => TRUE];
     $row['member_for']['data'] = $this->dateFormatter->formatTimeDiffSince($entity->getCreatedTime(), $options)->toRenderable();
     $last_access = $this->dateFormatter->formatTimeDiffSince($entity->getLastAccessedTime(), $options);
     if ($entity->getLastAccessedTime()) {
         $row['access']['data']['#markup'] = $last_access->getString();
         CacheableMetadata::createFromObject($last_access)->applyTo($row['access']['data']);
     } else {
         $row['access']['data']['#markup'] = t('never');
     }
     return $row + parent::buildRow($entity);
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:28,代码来源:UserListBuilder.php

示例3: 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

示例4: 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

示例5: buildRow

 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $row['username']['data'] = array('#theme' => 'username', '#account' => $entity);
     $row['status'] = $entity->isActive() ? $this->t('active') : $this->t('blocked');
     $roles = user_role_names(TRUE);
     unset($roles[RoleInterface::AUTHENTICATED_ID]);
     $users_roles = array();
     foreach ($entity->getRoles() as $role) {
         if (isset($roles[$role])) {
             $users_roles[] = $roles[$role];
         }
     }
     asort($users_roles);
     $row['roles']['data'] = array('#theme' => 'item_list', '#items' => $users_roles);
     $row['member_for'] = $this->dateFormatter->formatTimeDiffSince($entity->getCreatedTime());
     $row['access'] = $entity->access ? $this->t('@time ago', array('@time' => $this->dateFormatter->formatTimeDiffSince($entity->getLastAccessedTime()))) : t('never');
     return $row + parent::buildRow($entity);
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:21,代码来源:UserListBuilder.php

示例6: 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

示例7: form

 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $view = $this->entity;
     $display_id = $this->displayID;
     // Do not allow the form to be cached, because $form_state->get('view') can become
     // stale between page requests.
     // See views_ui_ajax_get_form() for how this affects #ajax.
     // @todo To remove this and allow the form to be cacheable:
     //   - Change $form_state->get('view') to $form_state->getTemporary()['view'].
     //   - Add a #process function to initialize $form_state->getTemporary()['view']
     //     on cached form submissions.
     //   - Use \Drupal\Core\Form\FormStateInterface::loadInclude().
     $form_state->disableCache();
     if ($display_id) {
         if (!$view->getExecutable()->setDisplay($display_id)) {
             $form['#markup'] = $this->t('Invalid display id @display', array('@display' => $display_id));
             return $form;
         }
     }
     $form['#tree'] = TRUE;
     $form['#attached']['library'][] = 'core/jquery.ui.tabs';
     $form['#attached']['library'][] = 'core/jquery.ui.dialog';
     $form['#attached']['library'][] = 'core/drupal.states';
     $form['#attached']['library'][] = 'core/drupal.tabledrag';
     $form['#attached']['library'][] = 'views_ui/views_ui.admin';
     $form['#attached']['library'][] = 'views_ui/admin.styling';
     $form += array('#prefix' => '', '#suffix' => '');
     $view_status = $view->status() ? 'enabled' : 'disabled';
     $form['#prefix'] .= '<div class="views-edit-view views-admin ' . $view_status . ' clearfix">';
     $form['#suffix'] = '</div>' . $form['#suffix'];
     $form['#attributes']['class'] = array('form-edit');
     if ($view->isLocked()) {
         $username = array('#theme' => 'username', '#account' => $this->entityManager->getStorage('user')->load($view->lock->owner));
         $lock_message_substitutions = array('@user' => drupal_render($username), '@age' => $this->dateFormatter->formatTimeDiffSince($view->lock->updated), ':url' => $view->url('break-lock-form'));
         $form['locked'] = array('#type' => 'container', '#attributes' => array('class' => array('view-locked', 'messages', 'messages--warning')), '#children' => $this->t('This view is being edited by user @user, and is therefore locked from editing by others. This lock is @age old. Click here to <a href=":url">break this lock</a>.', $lock_message_substitutions), '#weight' => -10);
     } else {
         $form['changed'] = array('#type' => 'container', '#attributes' => array('class' => array('view-changed', 'messages', 'messages--warning')), '#children' => $this->t('You have unsaved changes.'), '#weight' => -10);
         if (empty($view->changed)) {
             $form['changed']['#attributes']['class'][] = 'js-hide';
         }
     }
     $form['displays'] = array('#prefix' => '<h1 class="unit-title clearfix">' . $this->t('Displays') . '</h1>', '#type' => 'container', '#attributes' => array('class' => array('views-displays')));
     $form['displays']['top'] = $this->renderDisplayTop($view);
     // The rest requires a display to be selected.
     if ($display_id) {
         $form_state->set('display_id', $display_id);
         // The part of the page where editing will take place.
         $form['displays']['settings'] = array('#type' => 'container', '#id' => 'edit-display-settings', '#attributes' => array('class' => array('edit-display-settings')));
         // Add a text that the display is disabled.
         if ($view->getExecutable()->displayHandlers->has($display_id)) {
             if (!$view->getExecutable()->displayHandlers->get($display_id)->isEnabled()) {
                 $form['displays']['settings']['disabled']['#markup'] = $this->t('This display is disabled.');
             }
         }
         // Add the edit display content
         $tab_content = $this->getDisplayTab($view);
         $tab_content['#theme_wrappers'] = array('container');
         $tab_content['#attributes'] = array('class' => array('views-display-tab'));
         $tab_content['#id'] = 'views-tab-' . $display_id;
         // Mark deleted displays as such.
         $display = $view->get('display');
         if (!empty($display[$display_id]['deleted'])) {
             $tab_content['#attributes']['class'][] = 'views-display-deleted';
         }
         // Mark disabled displays as such.
         if ($view->getExecutable()->displayHandlers->has($display_id) && !$view->getExecutable()->displayHandlers->get($display_id)->isEnabled()) {
             $tab_content['#attributes']['class'][] = 'views-display-disabled';
         }
         $form['displays']['settings']['settings_content'] = array('#type' => 'container', 'tab_content' => $tab_content);
     }
     return $form;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:75,代码来源:ViewEditForm.php


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