1
0
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:
Jordi Boggiano
2016-09-18 18:44:44 +02:00
parent ec945b60d4
commit 89683faff3
2 changed files with 59 additions and 2 deletions

View File

@@ -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;