mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-01 19:00:20 +02:00
Drop PHP7.0 hacks
This commit is contained in:
@@ -23,29 +23,9 @@ class DateTimeImmutable extends \DateTimeImmutable implements \JsonSerializable
|
|||||||
|
|
||||||
public function __construct($useMicroseconds, \DateTimeZone $timezone = null)
|
public function __construct($useMicroseconds, \DateTimeZone $timezone = null)
|
||||||
{
|
{
|
||||||
static $needsMicrosecondsHack = PHP_VERSION_ID < 70100;
|
|
||||||
|
|
||||||
$this->useMicroseconds = $useMicroseconds;
|
$this->useMicroseconds = $useMicroseconds;
|
||||||
$date = 'now';
|
|
||||||
|
|
||||||
if ($needsMicrosecondsHack && $useMicroseconds) {
|
parent::__construct('now', $timezone);
|
||||||
$timestamp = microtime(true);
|
|
||||||
|
|
||||||
// apply offset of the timezone as microtime() is always UTC
|
|
||||||
if ($timezone && $timezone->getName() !== 'UTC') {
|
|
||||||
$timestamp += (new \DateTime('now', $timezone))->getOffset();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Circumvent DateTimeImmutable::createFromFormat() which always returns \DateTimeImmutable instead of `static`
|
|
||||||
// @link https://bugs.php.net/bug.php?id=60302
|
|
||||||
//
|
|
||||||
// So we create a DateTime but then format it so we
|
|
||||||
// can re-create one using the right class
|
|
||||||
$dt = self::createFromFormat('U.u', sprintf('%.6F', $timestamp));
|
|
||||||
$date = $dt->format('Y-m-d H:i:s.u');
|
|
||||||
}
|
|
||||||
|
|
||||||
parent::__construct($date, $timezone);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function jsonSerialize(): string
|
public function jsonSerialize(): string
|
||||||
|
Reference in New Issue
Block a user