diff --git a/core/lib/Drupal/Core/Datetime/DateFormatter.php b/core/lib/Drupal/Core/Datetime/DateFormatter.php index a4a8151..02e8b92 100644 --- a/core/lib/Drupal/Core/Datetime/DateFormatter.php +++ b/core/lib/Drupal/Core/Datetime/DateFormatter.php @@ -357,7 +357,6 @@ public function formatDiff($from, $to, $options = array()) { $interval = $date_time_to->diff($date_time_from); $granularity = $options['granularity']; - $parts = 0; $output = ''; // We loop over the keys provided by \DateInterval explicitly. Since we @@ -382,13 +381,13 @@ public function formatDiff($from, $to, $options = array()) { $interval_output = ''; $days = $interval->d; $weeks = floor($days / 7); - if ($days >= 7) { + if ($weeks) { $interval_output .= $this->formatPlural($weeks, '1 week', '@count weeks', array(), array('langcode' => $options['langcode'])); $days -= $weeks * 7; $granularity--; } - if (($parts == 0 || $weeks > 0) && $granularity > 0 && $days > 0) { + if ((!$output || $weeks > 0) && $granularity > 0 && $days > 0) { $interval_output .= ($interval_output ? ' ' : '') . $this->formatPlural($days, '1 day', '@count days', array(), array('langcode' => $options['langcode'])); } break; @@ -408,9 +407,8 @@ public function formatDiff($from, $to, $options = array()) { } $output .= ($output && $interval_output ? ' ' : '') . $interval_output; $granularity--; - $parts++; } - elseif ($parts) { + elseif ($output) { // Break if there was previous output but not any output at this level, // to avoid skipping levels and getting output like "1 year 1 second". break;