From 8e56a52772ec55dabb9cbcded130abc82c350cd6 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Tue, 21 Sep 2021 17:31:02 +0100
Subject: [PATCH] Issue #3236798 by alexpott:
 \Drupal\Core\Datetime\DateFormatter::formatInterval() causes deprecations in
 PHP 8.1

---
 core/includes/batch.inc                                    | 6 +++---
 core/modules/views/src/Plugin/views/field/TimeInterval.php | 2 +-
 core/scripts/run-tests.sh                                  | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/core/includes/batch.inc b/core/includes/batch.inc
index af7987fd8fe0..ebee3eb35cd7 100644
--- a/core/includes/batch.inc
+++ b/core/includes/batch.inc
@@ -360,9 +360,9 @@ function _batch_process() {
       '@total'      => $total,
       '@current'    => floor($current),
       '@percentage' => $percentage,
-      '@elapsed'    => \Drupal::service('date.formatter')->formatInterval($elapsed / 1000),
+      '@elapsed'    => \Drupal::service('date.formatter')->formatInterval((int) ($elapsed / 1000)),
       // If possible, estimate remaining processing time.
-      '@estimate'   => ($current > 0) ? \Drupal::service('date.formatter')->formatInterval(($elapsed * ($total - $current) / $current) / 1000) : '-',
+      '@estimate'   => ($current > 0) ? \Drupal::service('date.formatter')->formatInterval((int) (($elapsed * ($total - $current) / $current) / 1000)) : '-',
     ];
     $message    = strtr($progress_message, $values);
 
@@ -453,7 +453,7 @@ function _batch_finished() {
       if (is_callable($batch_set['finished'])) {
         $queue = _batch_queue($batch_set);
         $operations = $queue->getAllItems();
-        $batch_set_result = call_user_func_array($batch_set['finished'], [$batch_set['success'], $batch_set['results'], $operations, \Drupal::service('date.formatter')->formatInterval($batch_set['elapsed'] / 1000)]);
+        $batch_set_result = call_user_func_array($batch_set['finished'], [$batch_set['success'], $batch_set['results'], $operations, \Drupal::service('date.formatter')->formatInterval((int) ($batch_set['elapsed'] / 1000))]);
         // If a batch 'finished' callback requested a redirect after the batch
         // is complete, save that for later use. If more than one batch set
         // returned a redirect, the last one is used.
diff --git a/core/modules/views/src/Plugin/views/field/TimeInterval.php b/core/modules/views/src/Plugin/views/field/TimeInterval.php
index 79cd190605a7..77924234d1ce 100644
--- a/core/modules/views/src/Plugin/views/field/TimeInterval.php
+++ b/core/modules/views/src/Plugin/views/field/TimeInterval.php
@@ -82,7 +82,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    */
   public function render(ResultRow $values) {
     $value = $values->{$this->field_alias};
-    return $this->dateFormatter->formatInterval($value, isset($this->options['granularity']) ? $this->options['granularity'] : 2);
+    return $this->dateFormatter->formatInterval((int) $value, isset($this->options['granularity']) ? $this->options['granularity'] : 2);
   }
 
 }
diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh
index 40ed2b3f2f40..2163902ba148 100755
--- a/core/scripts/run-tests.sh
+++ b/core/scripts/run-tests.sh
@@ -1311,7 +1311,7 @@ function simpletest_script_reporter_write_xml_results() {
 function simpletest_script_reporter_timer_stop() {
   echo "\n";
   $end = Timer::stop('run-tests');
-  echo "Test run duration: " . \Drupal::service('date.formatter')->formatInterval($end['time'] / 1000);
+  echo "Test run duration: " . \Drupal::service('date.formatter')->formatInterval((int) ($end['time'] / 1000));
   echo "\n\n";
 }
 
-- 
GitLab