diff options
author | Jordi Boggiano <j.boggiano@seld.be> | 2016-09-19 13:29:35 +0200 |
---|---|---|
committer | Jordi Boggiano <j.boggiano@seld.be> | 2016-09-19 13:29:35 +0200 |
commit | 5558c3b26b86f090e81068a38c05135f4a07d9cc (patch) | |
tree | b7ff5882ccd0a3ae7f89e31d02d80cfd79e07ea2 /src | |
parent | 89683faff3ac100d2ee52d072acc7bddb988475d (diff) | |
download | monolog-5558c3b26b86f090e81068a38c05135f4a07d9cc.zip monolog-5558c3b26b86f090e81068a38c05135f4a07d9cc.tar.gz monolog-5558c3b26b86f090e81068a38c05135f4a07d9cc.tar.bz2 |
Minor clarifications
Diffstat (limited to 'src')
-rw-r--r-- | src/Monolog/DateTimeImmutable.php | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/Monolog/DateTimeImmutable.php b/src/Monolog/DateTimeImmutable.php index 30ef809..45b80c7 100644 --- a/src/Monolog/DateTimeImmutable.php +++ b/src/Monolog/DateTimeImmutable.php @@ -23,10 +23,10 @@ class DateTimeImmutable extends \DateTimeImmutable implements \JsonSerializable public function __construct($useMicroseconds, \DateTimeZone $timezone = null) { + $this->useMicroseconds = $useMicroseconds; $date = 'now'; + if ($useMicroseconds) { - // Circumvent DateTimeImmutable::createFromFormat() which always returns \DateTimeImmutable instead of `static` - // @link https://bugs.php.net/bug.php?id=60302 $timestamp = microtime(true); // apply offset of the timezone as microtime() is always UTC @@ -34,13 +34,16 @@ class DateTimeImmutable extends \DateTimeImmutable implements \JsonSerializable $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); - - $this->useMicroseconds = $useMicroseconds; } public function jsonSerialize(): string |