1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-05 20:57:36 +02:00

Fixing date/time formatting in MongoDBFormatter.

This commit is contained in:
Nikola Posa
2016-11-09 19:16:42 +01:00
parent cb88cc82de
commit b064f86b41

View File

@@ -104,7 +104,27 @@ class MongoDBFormatter implements FormatterInterface
}
protected function formatDate(\DateTimeInterface $value, int $nestingLevel): UTCDateTime
{
if (version_compare(phpversion('mongodb'), '1.1.9', '<=')) {
return $this->legacyGetMongoDbDateTime($value);
}
return $this->getMongoDbDateTime($value);
}
final protected function getMongoDbDateTime(\DateTimeInterface $value): UTCDateTime
{
return new UTCDateTime((string) floor($value->format('U.u') * 1000));
}
final protected function legacyGetMongoDbDateTime(\DateTimeInterface $value): UTCDateTime
{
$milliseconds = floor($value->format('U.u') * 1000);
$milliseconds = (PHP_INT_SIZE == 8) //64-bit OS?
? (int) $milliseconds
: (string) $milliseconds;
return new UTCDateTime($milliseconds);
}
}