diff --git a/core/lib/Drupal/Core/Datetime/DateFormatter.php b/core/lib/Drupal/Core/Datetime/DateFormatter.php index 82e9969..09bbd6f 100644 --- a/core/lib/Drupal/Core/Datetime/DateFormatter.php +++ b/core/lib/Drupal/Core/Datetime/DateFormatter.php @@ -176,6 +176,7 @@ public function format($timestamp, $type = 'medium', $format = '', $timezone = N * A translated string representation of the interval. */ public function formatInterval($interval, $granularity = 2, $langcode = NULL) { + $parts = 0; $output = ''; foreach ($this->units as $key => $value) { $key = explode('|', $key); @@ -183,6 +184,10 @@ public function formatInterval($interval, $granularity = 2, $langcode = NULL) { $output .= ($output ? ' ' : '') . $this->formatPlural(floor($interval / $value), $key[0], $key[1], array(), array('langcode' => $langcode)); $interval %= $value; $granularity--; + $parts++; + } + elseif ($parts) { + break; } if ($granularity == 0) { diff --git a/core/tests/Drupal/Tests/Core/Datetime/DateTest.php b/core/tests/Drupal/Tests/Core/Datetime/DateTest.php index 1cbed5e..f530730 100644 --- a/core/tests/Drupal/Tests/Core/Datetime/DateTest.php +++ b/core/tests/Drupal/Tests/Core/Datetime/DateTest.php @@ -110,7 +110,7 @@ public function providerTestFormatInterval() { array(121, 2, '2 min 1 sec'), // Check for hours with minutes and seconds. array(3601, 1, '1 hour'), - array(3601, 2, '1 hour 1 sec'), + array(3601, 2, '1 hour'), // Check for higher units. array(86401, 1, '1 day'), array(604800, 1, '1 week'),