Skip to content

Commit

Permalink
Use sprintf() in Target::getTime() (#16883)
Browse files Browse the repository at this point in the history
* Use `sprintf()` in `Target::getTime()`.

* Changelog line [skip ci].
  • Loading branch information
rob006 authored and cebe committed Nov 28, 2018
1 parent d7ffda0 commit 5349132
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions framework/log/Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]) : '');
}
}
6 changes: 3 additions & 3 deletions tests/framework/log/TargetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 5349132

Please sign in to comment.