Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow precision 0 in Carbon DBAL types #2537

Merged
merged 3 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()));
kylekatarnls marked this conversation as resolved.
Show resolved Hide resolved
Expand Down