Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecated warning implicit conversion from float (#20083) #20144

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion framework/i18n/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@
} 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));

Check warning on line 1062 in framework/i18n/Formatter.php

View check run for this annotation

Codecov / codecov/patch

framework/i18n/Formatter.php#L1062

Added line #L1062 was not covered by tests
$interval = $valueDateTime->diff($zeroDateTime);
} elseif (strncmp($value, 'P-', 2) === 0) {
$interval = new DateInterval('P' . substr($value, 2));
Expand Down
1 change: 1 addition & 0 deletions tests/framework/i18n/FormatterDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Loading