diff options
author | Jordi Boggiano <j.boggiano@seld.be> | 2016-09-18 18:44:44 +0200 |
---|---|---|
committer | Jordi Boggiano <j.boggiano@seld.be> | 2016-09-19 13:24:54 +0200 |
commit | 89683faff3ac100d2ee52d072acc7bddb988475d (patch) | |
tree | 9453abed2820b77a0db6aa94438ec11aeb689380 /src | |
parent | ec945b60d462a228ee290aaa4e0c401f50d2531a (diff) | |
download | monolog-89683faff3ac100d2ee52d072acc7bddb988475d.zip monolog-89683faff3ac100d2ee52d072acc7bddb988475d.tar.gz monolog-89683faff3ac100d2ee52d072acc7bddb988475d.tar.bz2 |
Fixes microsecond timezone support, fixes #832
Diffstat (limited to 'src')
-rw-r--r-- | src/Monolog/DateTimeImmutable.php | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/Monolog/DateTimeImmutable.php b/src/Monolog/DateTimeImmutable.php index 6ca786c..30ef809 100644 --- a/src/Monolog/DateTimeImmutable.php +++ b/src/Monolog/DateTimeImmutable.php @@ -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; |