diff --git a/src/Carbon/Doctrine/CarbonTypeConverter.php b/src/Carbon/Doctrine/CarbonTypeConverter.php index 0d64347cff..ecfe17e793 100644 --- a/src/Carbon/Doctrine/CarbonTypeConverter.php +++ b/src/Carbon/Doctrine/CarbonTypeConverter.php @@ -36,9 +36,16 @@ protected function getCarbonClassName(): string */ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { - $precision = ($fieldDeclaration['precision'] ?? 10) === 10 - ? DateTimeDefaultPrecision::get() - : $fieldDeclaration['precision']; + $precision = $fieldDeclaration['precision'] ?: 10; + + if ($fieldDeclaration['secondPrecision'] ?? false) { + $precision = 0; + } + + if ($precision === 10) { + $precision = DateTimeDefaultPrecision::get(); + } + $type = parent::getSQLDeclaration($fieldDeclaration, $platform); if (!$precision) { diff --git a/tests/Doctrine/CarbonTypesTest.php b/tests/Doctrine/CarbonTypesTest.php index 0a7f4eea14..0f12a59f97 100644 --- a/tests/Doctrine/CarbonTypesTest.php +++ b/tests/Doctrine/CarbonTypesTest.php @@ -65,7 +65,8 @@ public function testGetSQLDeclaration(string $name) $this->assertSame(6, $precision); $this->assertSame('DATETIME', $type->getSQLDeclaration([ - 'precision' => 0, + 'precision' => null, + 'secondPrecision' => true, ], new MySQL57Platform())); $this->assertSame('DATETIME(3)', $type->getSQLDeclaration([ @@ -73,7 +74,8 @@ public function testGetSQLDeclaration(string $name) ], new MySQL57Platform())); $this->assertSame('TIMESTAMP(0)', $type->getSQLDeclaration([ - 'precision' => 0, + 'precision' => null, + 'secondPrecision' => true, ], new DB2Platform())); $this->assertSame('TIMESTAMP(6)', $type->getSQLDeclaration([