mirror of
https://github.com/Seldaek/monolog.git
synced 2025-10-21 16:46:11 +02:00
Fixes microsecond timezone support, fixes #832
This commit is contained in:
@@ -28,9 +28,16 @@ class DateTimeImmutable extends \DateTimeImmutable implements \JsonSerializable
|
||||
// Circumvent DateTimeImmutable::createFromFormat() which always returns \DateTimeImmutable instead of `static`
|
||||
// @link https://bugs.php.net/bug.php?id=60302
|
||||
$timestamp = microtime(true);
|
||||
$microseconds = sprintf("%06d", ($timestamp - floor($timestamp)) * 1000000);
|
||||
$date = date('Y-m-d H:i:s.' . $microseconds, (int) $timestamp);
|
||||
|
||||
// apply offset of the timezone as microtime() is always UTC
|
||||
if ($timezone && $timezone->getName() !== 'UTC') {
|
||||
$timestamp += (new \DateTime('now', $timezone))->getOffset();
|
||||
}
|
||||
|
||||
$dt = self::createFromFormat('U.u', sprintf('%.6F', $timestamp));
|
||||
$date = $dt->format('Y-m-d H:i:s.u');
|
||||
}
|
||||
|
||||
parent::__construct($date, $timezone);
|
||||
|
||||
$this->useMicroseconds = $useMicroseconds;
|
||||
|
Reference in New Issue
Block a user