From 5349132043aa157b8182c8aaae6d63116cf3aa6d Mon Sep 17 00:00:00 2001 From: Robert Korulczyk Date: Wed, 28 Nov 2018 08:22:04 +0100 Subject: [PATCH] Use `sprintf()` in `Target::getTime()` (#16883) * Use `sprintf()` in `Target::getTime()`. * Changelog line [skip ci]. --- framework/CHANGELOG.md | 1 + framework/log/Target.php | 4 ++-- tests/framework/log/TargetTest.php | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index ef69e2026d4..ee56e5891c8 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -78,6 +78,7 @@ Yii Framework 2 Change Log - Bug #10843: Additional hidden input rendered by `yii\helpers\BaseHtml` methods inherits `disabled` HTML option if provided and set to `true` (bizley) - Bug #16424: `yii\db\Transaction::begin()` throws now `NotSupportedException` for nested transaction and DBMS not supporting savepoints (bizley) - Bug #15204: `yii\helpers\BaseInflector::slug()` is not removing substrings matching provided replacement from given string anymore (bizley) +- Bug #15528: Fix timestamp formatting to always use decimal notation in `yii\log\Target::getTime()` (rob006) - Bug #16101: Fixed Error Handler to clear registered meta tags, link tags, css/js scripts and files in error view (bizley) - Bug #16836: Fix `yii\mutex\MysqlMutex` to handle locks with names longer than 64 characters (rob006) - Bug #16838: `yii\mutex\Mutex::acquire()` no longer returns `true` if lock is already acquired by the same component in the same process (rob006) diff --git a/framework/log/Target.php b/framework/log/Target.php index f49d76ab0e3..c2d93449235 100644 --- a/framework/log/Target.php +++ b/framework/log/Target.php @@ -364,8 +364,8 @@ public function getEnabled() */ protected function getTime($timestamp) { - $parts = explode('.', StringHelper::floatToString($timestamp)); + $parts = explode('.', sprintf('%F', $timestamp)); - return date('Y-m-d H:i:s', $parts[0]) . ($this->microtime && isset($parts[1]) ? ('.' . $parts[1]) : ''); + return date('Y-m-d H:i:s', $parts[0]) . ($this->microtime ? ('.' . $parts[1]) : ''); } } diff --git a/tests/framework/log/TargetTest.php b/tests/framework/log/TargetTest.php index 332c5ce23cf..75040ae5cbd 100644 --- a/tests/framework/log/TargetTest.php +++ b/tests/framework/log/TargetTest.php @@ -204,15 +204,15 @@ public function testFormatMessage() $target->microtime = true; - $expectedWithMicro = '2017-10-16 13:26:30.6083 [info][application] message'; + $expectedWithMicro = '2017-10-16 13:26:30.608300 [info][application] message'; $formatted = $target->formatMessage([$text, $level, $category, $timestamp]); $this->assertSame($expectedWithMicro, $formatted); $timestamp = 1508160390; - $expectedWithoutMicro = '2017-10-16 13:26:30 [info][application] message'; + $expectedWithMicro = '2017-10-16 13:26:30.000000 [info][application] message'; $formatted = $target->formatMessage([$text, $level, $category, $timestamp]); - $this->assertSame($expectedWithoutMicro, $formatted); + $this->assertSame($expectedWithMicro, $formatted); } }