From e02e131f3e4594cc58a4feaaeb86e4d8fcc4fb3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=A1=D0=BF=D0=B8?= =?UTF-8?q?=D1=80=D0=BA=D0=BE=D0=B2?= Date: Sat, 23 Aug 2025 15:08:22 +0400 Subject: [PATCH 1/3] Replace deprecated `strftime` with `date` --- framework/requirements/YiiRequirementChecker.php | 2 +- tests/framework/behaviors/TimestampBehaviorTest.php | 10 +++++----- tests/framework/db/CommandTest.php | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/framework/requirements/YiiRequirementChecker.php b/framework/requirements/YiiRequirementChecker.php index 45675cd716c..955d2294186 100644 --- a/framework/requirements/YiiRequirementChecker.php +++ b/framework/requirements/YiiRequirementChecker.php @@ -399,6 +399,6 @@ function getServerInfo() */ function getNowDate() { - return @strftime('%Y-%m-%d %H:%M', time()); + return date('Y-m-d H:i'); } } diff --git a/tests/framework/behaviors/TimestampBehaviorTest.php b/tests/framework/behaviors/TimestampBehaviorTest.php index 8a64fcb90f4..af3f0d28877 100644 --- a/tests/framework/behaviors/TimestampBehaviorTest.php +++ b/tests/framework/behaviors/TimestampBehaviorTest.php @@ -133,7 +133,7 @@ public function expressionProvider() { return [ [function () { return '2015-01-01'; }, '2015-01-01'], - [new Expression("strftime('%Y')"), date('Y')], + [new Expression("date('Y')"), date('Y')], ['2015-10-20', '2015-10-20'], [time(), time()], [[$this, 'arrayCallable'], '2015-10-20'], @@ -179,7 +179,7 @@ public function testUpdateRecordExpression() ActiveRecordTimestamp::$behaviors = [ 'timestamp' => [ 'class' => TimestampBehavior::className(), - 'value' => new Expression("strftime('%Y')"), + 'value' => new Expression("date('Y')"), ], ]; $model = new ActiveRecordTimestamp(); @@ -202,7 +202,7 @@ public function testTouchingNewRecordGeneratesException() ActiveRecordTimestamp::$behaviors = [ 'timestamp' => [ 'class' => TimestampBehavior::className(), - 'value' => new Expression("strftime('%Y')"), + 'value' => new Expression("date('Y')"), ], ]; $model = new ActiveRecordTimestamp(); @@ -217,7 +217,7 @@ public function testTouchingNotNewRecord() ActiveRecordTimestamp::$behaviors = [ 'timestamp' => [ 'class' => TimestampBehavior::className(), - 'value' => new Expression("strftime('%Y')"), + 'value' => new Expression("date('Y')"), ], ]; $model = new ActiveRecordTimestamp(); @@ -225,7 +225,7 @@ public function testTouchingNotNewRecord() $model->created_at = $enforcedTime; $model->updated_at = $enforcedTime; $model->save(false); - $expectedCreatedAt = new Expression("strftime('%Y')"); + $expectedCreatedAt = new Expression("date('Y')"); $model->touch('created_at'); diff --git a/tests/framework/db/CommandTest.php b/tests/framework/db/CommandTest.php index 1c0b203e9ad..ebc7a3c985a 100644 --- a/tests/framework/db/CommandTest.php +++ b/tests/framework/db/CommandTest.php @@ -652,7 +652,7 @@ public function testInsertExpression() $expression = 'YEAR(NOW())'; break; case 'sqlite': - $expression = "strftime('%Y')"; + $expression = "date('Y')"; break; case 'sqlsrv': $expression = 'YEAR(GETDATE())'; From 48076bfdef758b6632d24a2aef09b5442d59bed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=A1=D0=BF=D0=B8?= =?UTF-8?q?=D1=80=D0=BA=D0=BE=D0=B2?= Date: Sat, 23 Aug 2025 15:16:59 +0400 Subject: [PATCH 2/3] revert in db expression --- tests/framework/behaviors/TimestampBehaviorTest.php | 10 +++++----- tests/framework/db/CommandTest.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/framework/behaviors/TimestampBehaviorTest.php b/tests/framework/behaviors/TimestampBehaviorTest.php index af3f0d28877..8a64fcb90f4 100644 --- a/tests/framework/behaviors/TimestampBehaviorTest.php +++ b/tests/framework/behaviors/TimestampBehaviorTest.php @@ -133,7 +133,7 @@ public function expressionProvider() { return [ [function () { return '2015-01-01'; }, '2015-01-01'], - [new Expression("date('Y')"), date('Y')], + [new Expression("strftime('%Y')"), date('Y')], ['2015-10-20', '2015-10-20'], [time(), time()], [[$this, 'arrayCallable'], '2015-10-20'], @@ -179,7 +179,7 @@ public function testUpdateRecordExpression() ActiveRecordTimestamp::$behaviors = [ 'timestamp' => [ 'class' => TimestampBehavior::className(), - 'value' => new Expression("date('Y')"), + 'value' => new Expression("strftime('%Y')"), ], ]; $model = new ActiveRecordTimestamp(); @@ -202,7 +202,7 @@ public function testTouchingNewRecordGeneratesException() ActiveRecordTimestamp::$behaviors = [ 'timestamp' => [ 'class' => TimestampBehavior::className(), - 'value' => new Expression("date('Y')"), + 'value' => new Expression("strftime('%Y')"), ], ]; $model = new ActiveRecordTimestamp(); @@ -217,7 +217,7 @@ public function testTouchingNotNewRecord() ActiveRecordTimestamp::$behaviors = [ 'timestamp' => [ 'class' => TimestampBehavior::className(), - 'value' => new Expression("date('Y')"), + 'value' => new Expression("strftime('%Y')"), ], ]; $model = new ActiveRecordTimestamp(); @@ -225,7 +225,7 @@ public function testTouchingNotNewRecord() $model->created_at = $enforcedTime; $model->updated_at = $enforcedTime; $model->save(false); - $expectedCreatedAt = new Expression("date('Y')"); + $expectedCreatedAt = new Expression("strftime('%Y')"); $model->touch('created_at'); diff --git a/tests/framework/db/CommandTest.php b/tests/framework/db/CommandTest.php index ebc7a3c985a..1c0b203e9ad 100644 --- a/tests/framework/db/CommandTest.php +++ b/tests/framework/db/CommandTest.php @@ -652,7 +652,7 @@ public function testInsertExpression() $expression = 'YEAR(NOW())'; break; case 'sqlite': - $expression = "date('Y')"; + $expression = "strftime('%Y')"; break; case 'sqlsrv': $expression = 'YEAR(GETDATE())'; From b4c5e33623631e7e7d02c542126b93a31694b41e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=A1=D0=BF=D0=B8?= =?UTF-8?q?=D1=80=D0=BA=D0=BE=D0=B2?= Date: Sat, 23 Aug 2025 15:20:34 +0400 Subject: [PATCH 3/3] changelog --- framework/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 48339bb37f4..dda8e6c9a81 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -17,6 +17,7 @@ Yii Framework 2 Change Log - Enh #20480: Add PHPStan/Psalm annotations for `ServiceLocator::get` (max-s-lab) - Bug #20447: Fix behavior for `yii\web\Controller::bindActionParams` around `mixed` type (chriscpty) - Bug #20492: Fix deprecation of `finfo_close()` in PHP `8.5` by conditionally closing the resource (terabytesoftw) +- Bug #20489: Replace deprecated `strftime` with `date` in `YiiRequirementChecker` (max-s-lab) 2.0.53 June 27, 2025 --------------------