Skip to content

Commit

Permalink
Allow precision 0 in Carbon DBAL types
Browse files Browse the repository at this point in the history
  • Loading branch information
kdaniel95 committed Jan 13, 2022
1 parent b989a73 commit 19a0881
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Carbon/Doctrine/CarbonTypeConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function getCarbonClassName(): string
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
$precision = ($fieldDeclaration['precision'] ?: 10) === 10
$precision = ($fieldDeclaration['precision'] ?? 10) === 10
? DateTimeDefaultPrecision::get()
: $fieldDeclaration['precision'];
$type = parent::getSQLDeclaration($fieldDeclaration, $platform);
Expand Down
8 changes: 8 additions & 0 deletions tests/Doctrine/CarbonTypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,18 @@ public function testGetSQLDeclaration(string $name)
$precision = DateTimeDefaultPrecision::get();
$this->assertSame(6, $precision);

$this->assertSame('DATETIME', $type->getSQLDeclaration([
'precision' => 0,
], new MySQL57Platform()));

$this->assertSame('DATETIME(3)', $type->getSQLDeclaration([
'precision' => 3,
], new MySQL57Platform()));

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

$this->assertSame('TIMESTAMP(6)', $type->getSQLDeclaration([
'precision' => null,
], new DB2Platform()));
Expand Down

0 comments on commit 19a0881

Please sign in to comment.