You are here

protected function ModerationSidebarController::getPrettyTime in Moderation Sidebar 8

Formats a timestamp to be presentable to end users.

Parameters

int $time: The revision timestamp.

Return value

\Drupal\Core\StringTranslation\TranslatableMarkup Markup representing a presentable time.

2 calls to ModerationSidebarController::getPrettyTime()
ModerationSidebarController::revisionOverview in src/Controller/ModerationSidebarController.php
Generates an simple list of revisions for a node.
ModerationSidebarController::sideBar in src/Controller/ModerationSidebarController.php
Displays information relevant to moderating an entity in-line.

File

src/Controller/ModerationSidebarController.php, line 624

Class

ModerationSidebarController
Endpoints for the Moderation Sidebar module.

Namespace

Drupal\moderation_sidebar\Controller

Code

protected function getPrettyTime($time) {
  $too_old = strtotime('-1 month');

  // Show formatted time differences for edits younger than a month.
  if ($time > $too_old) {
    $diff = $this->dateFormatter
      ->formatTimeDiffSince($time, [
      'granularity' => 1,
    ]);
    $time_pretty = $this
      ->t('@diff ago', [
      '@diff' => $diff,
    ]);
  }
  else {
    $date = date('m/d/Y - h:i A', $time);
    $time_pretty = $this
      ->t('on @date', [
      '@date' => $date,
    ]);
  }
  return $time_pretty;
}