Skip to content

Commit fd0ad45

Browse files
authored
Create UTCDateTime from DateTimeInterface directly (#2736)
Supported since ext-mongodb 1.2 mongodb/mongo-php-driver#336
1 parent 2e49ae1 commit fd0ad45

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/Doctrine/ODM/MongoDB/Types/DateType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function convertToDatabaseValue($value)
9090

9191
$datetime = static::getDateTime($value);
9292

93-
return new UTCDateTime((int) $datetime->format('Uv'));
93+
return new UTCDateTime($datetime);
9494
}
9595

9696
public function convertToPHPValue($value)
@@ -104,7 +104,7 @@ public function convertToPHPValue($value)
104104

105105
public function closureToMongo(): string
106106
{
107-
return 'if ($value === null || $value instanceof \MongoDB\BSON\UTCDateTime) { $return = $value; } else { $datetime = \\' . static::class . '::getDateTime($value); $return = new \MongoDB\BSON\UTCDateTime((int) $datetime->format(\'Uv\')); }';
107+
return 'if ($value === null || $value instanceof \MongoDB\BSON\UTCDateTime) { $return = $value; } else { $datetime = \\' . static::class . '::getDateTime($value); $return = new \MongoDB\BSON\UTCDateTime($datetime); }';
108108
}
109109

110110
public function closureToPHP(): string

0 commit comments

Comments
 (0)