You are here

public function DateFormatter::formatTimeDiffUntil in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Datetime/DateFormatter.php \Drupal\Core\Datetime\DateFormatter::formatTimeDiffUntil()

Formats the time difference from the current request time to a timestamp.

Parameters

$timestamp: A UNIX timestamp to compare against the current request time.

array $options: (optional) An associative array with additional options. The following keys can be used:

  • granularity: An integer value that signals how many different units to display in the string. Defaults to 2.
  • langcode: The language code for the language used to format the date. Defaults to NULL, which results in the user interface language for the page being used.
  • strict: A Boolean value indicating whether or not the timestamp can be before the current request time. If TRUE (default) and $timestamp is before the current request time, the result string will be "0 seconds". If FALSE and $timestamp is before the current request time, the result string will be the formatted time difference.

Return value

string A translated string representation of the difference between the given timestamp and the current request time. This interval is always positive.

Overrides DateFormatterInterface::formatTimeDiffUntil

See also

\Drupal\Core\Datetime\DateFormatterInterface::formatDiff()

\Drupal\Core\Datetime\DateFormatterInterface::formatTimeDiffSince()

File

core/lib/Drupal/Core/Datetime/DateFormatter.php, line 187
Contains \Drupal\Core\Datetime\DateFormatter.

Class

DateFormatter
Provides a service to handle various date related functionality.

Namespace

Drupal\Core\Datetime

Code

public function formatTimeDiffUntil($timestamp, $options = array()) {
  $request_time = $this->requestStack
    ->getCurrentRequest()->server
    ->get('REQUEST_TIME');
  return $this
    ->formatDiff($request_time, $timestamp, $options);
}