Skip to content

Commit

Permalink
Change, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kdaniel95 committed Jan 21, 2022
1 parent 19a0881 commit 942ba23
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/Carbon/Doctrine/CarbonTypeConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions tests/Doctrine/CarbonTypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,17 @@ 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([
'precision' => 3,
], new MySQL57Platform()));

$this->assertSame('TIMESTAMP(0)', $type->getSQLDeclaration([
'precision' => 0,
'precision' => null,
'secondPrecision' => true,
], new DB2Platform()));

$this->assertSame('TIMESTAMP(6)', $type->getSQLDeclaration([
Expand Down

0 comments on commit 942ba23

Please sign in to comment.