From 8f47e12463073190515efc5d61a82e74d2bbe8d5 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 17 Nov 2016 11:23:34 +0100 Subject: [PATCH] Fix PHP7.1 DateTime support --- src/Monolog/Logger.php | 3 ++- tests/Monolog/LoggerTest.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Monolog/Logger.php b/src/Monolog/Logger.php index 2fbc02c7..49d00af1 100644 --- a/src/Monolog/Logger.php +++ b/src/Monolog/Logger.php @@ -311,7 +311,8 @@ class Logger implements LoggerInterface 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); } else { $ts = new \DateTime(null, static::$timezone); diff --git a/tests/Monolog/LoggerTest.php b/tests/Monolog/LoggerTest.php index c0bd1da9..1ecc34a0 100644 --- a/tests/Monolog/LoggerTest.php +++ b/tests/Monolog/LoggerTest.php @@ -542,7 +542,7 @@ class LoggerTest extends \PHPUnit_Framework_TestCase return array( // this has a very small chance of a false negative (1/10^6) 'with microseconds' => array(true, 'assertNotSame'), - 'without microseconds' => array(false, 'assertSame'), + 'without microseconds' => array(false, PHP_VERSION_ID >= 70100 ? 'assertNotSame' : 'assertSame'), ); } }