1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-05 12:47:39 +02:00

Fix PHP7.1 DateTime support

This commit is contained in:
Jordi Boggiano
2016-11-17 11:23:34 +01:00
parent 9d43c66cc6
commit 8f47e12463
2 changed files with 3 additions and 2 deletions

View File

@@ -311,7 +311,8 @@ class Logger implements LoggerInterface
static::$timezone = new \DateTimeZone(date_default_timezone_get() ?: 'UTC'); static::$timezone = new \DateTimeZone(date_default_timezone_get() ?: 'UTC');
} }
if ($this->microsecondTimestamps) { // php7.1+ always has microseconds enabled, so we do not need this hack
if ($this->microsecondTimestamps && PHP_VERSION_ID < 70100) {
$ts = \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)), static::$timezone); $ts = \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)), static::$timezone);
} else { } else {
$ts = new \DateTime(null, static::$timezone); $ts = new \DateTime(null, static::$timezone);

View File

@@ -542,7 +542,7 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
return array( return array(
// this has a very small chance of a false negative (1/10^6) // this has a very small chance of a false negative (1/10^6)
'with microseconds' => array(true, 'assertNotSame'), 'with microseconds' => array(true, 'assertNotSame'),
'without microseconds' => array(false, 'assertSame'), 'without microseconds' => array(false, PHP_VERSION_ID >= 70100 ? 'assertNotSame' : 'assertSame'),
); );
} }
} }