mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-05 20:57:36 +02:00
Merge pull request #884 from nikolaposa/fix/mongodb-formatter-date
Fixing date/time formatting in MongoDBFormatter
This commit is contained in:
@@ -104,7 +104,27 @@ class MongoDBFormatter implements FormatterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function formatDate(\DateTimeInterface $value, int $nestingLevel): UTCDateTime
|
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));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user