From e56e77732506a98bb79febe85d2bcb83b72e0b33 Mon Sep 17 00:00:00 2001 From: skepticspriggan <91023755+skepticspriggan@users.noreply.github.com> Date: Tue, 2 Apr 2024 23:40:02 +0200 Subject: [PATCH] Fix #20083: Fix deprecated warning implicit conversion from float --- framework/CHANGELOG.md | 1 + framework/i18n/Formatter.php | 2 +- tests/framework/i18n/FormatterDateTest.php | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 84c56493049..593400797e3 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -20,6 +20,7 @@ Yii Framework 2 Change Log - Enh #20042: Add empty array check to `ActiveQueryTrait::findWith()` (renkas) - Enh #20032: Added `yii\helpers\BaseStringHelper::mask()` method for string masking with multibyte support (salehhashemi1992) - Enh #20034: Added `yii\helpers\BaseStringHelper::findBetween()` to retrieve a substring that lies between two strings (salehhashemi1992) +- Bug #20083: Fix deprecated warning implicit conversion from float (skepticspriggan) - Enh #20121: Added `yiisoft/yii2-coding-standards` to composer `require-dev` and lint code to comply with PSR12 (razvanphp) - Enh #20134: Raise minimum `PHP` version to `7.3` (@terabytesoftw) - Bug #20141: Update `ezyang/htmlpurifier` dependency to version `4.17` (@terabytesoftw) diff --git a/framework/i18n/Formatter.php b/framework/i18n/Formatter.php index b72385eaa59..c1b9d9106eb 100644 --- a/framework/i18n/Formatter.php +++ b/framework/i18n/Formatter.php @@ -1059,7 +1059,7 @@ public function asDuration($value, $implodeString = ', ', $negativeSign = '-') } elseif (is_numeric($value)) { $isNegative = $value < 0; $zeroDateTime = (new DateTime())->setTimestamp(0); - $valueDateTime = (new DateTime())->setTimestamp(abs($value)); + $valueDateTime = (new DateTime())->setTimestamp(abs((int) $value)); $interval = $valueDateTime->diff($zeroDateTime); } elseif (strncmp($value, 'P-', 2) === 0) { $interval = new DateInterval('P' . substr($value, 2)); diff --git a/tests/framework/i18n/FormatterDateTest.php b/tests/framework/i18n/FormatterDateTest.php index c62ff491b11..1af75fc49e0 100644 --- a/tests/framework/i18n/FormatterDateTest.php +++ b/tests/framework/i18n/FormatterDateTest.php @@ -536,6 +536,7 @@ public function testAsDuration() // other options $this->assertSame('minus 244 seconds', $this->formatter->asDuration($interval_244_seconds, ' and ', 'minus ')); $this->assertSame('minus 4 minutes and 4 seconds', $this->formatter->asDuration(-244, ' and ', 'minus ')); + $this->assertSame('1 second', $this->formatter->asDuration(1.5)); // Pass a inverted DateInterval string $this->assertSame('-1 year, 2 months, 10 days, 2 hours, 30 minutes', $this->formatter->asDuration('2008-05-11T15:30:00Z/2007-03-01T13:00:00Z'));