protected function TimestampAgoFormatter::formatTimestamp in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampAgoFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\TimestampAgoFormatter::formatTimestamp()
Formats a timestamp.
Parameters
int $timestamp: A UNIX timestamp to format.
Return value
string The formatted timestamp string using the past or future format setting.
2 calls to TimestampAgoFormatter::formatTimestamp()
- TimestampAgoFormatter::settingsSummary in core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldFormatter/ TimestampAgoFormatter.php - Returns a short summary for the current formatter settings.
- TimestampAgoFormatter::viewElements in core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldFormatter/ TimestampAgoFormatter.php - Builds a renderable array for a field value.
File
- core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldFormatter/ TimestampAgoFormatter.php, line 182 - Contains \Drupal\Core\Field\Plugin\Field\FieldFormatter\TimestampAgoFormatter.
Class
- TimestampAgoFormatter
- Plugin implementation of the 'timestamp' formatter as time ago.
Namespace
Drupal\Core\Field\Plugin\Field\FieldFormatterCode
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),
]);
}
}